【问题标题】:Liquid coding (Shopify) "and" and "elsif" not functioning together液体编码(Shopify)“and”和“elsif”不能一起工作
【发布时间】:2021-05-20 23:36:30
【问题描述】:

我在开设自己的 Shopify 商店时不熟悉液体编码(尽管我有一些编码经验)。我目前正试图让这段代码正常工作。我在液体文件中为每个变量添加了 3 个文本选项。这个想法是,当满足标准时,它将显示适当的文本选项。请参阅此处的代码字符串以获取参考。

  {% if section.settings.free_shipping_announcement_bar %}
    
        {% assign promote_text = section.settings.promote_free_shipping_text | escape %}
        {% assign unlocked_text = section.settings.unlocked_free_shipping_text | escape %}
        {% assign unlocked_del_text = section.settings.unlocked_free_delivery_text | escape %}
        {% assign threshold = section.settings.free_shipping_threshold | times: 100 %}
        
        {% assign value_left = threshold | minus:cart.total_price %}
        {% assign value_left_money = value_left | money %}

         <div class="announcement-bar">
       
             {% if value_left <= 0 %}
            <p class="announcement-bar__message">{{unlocked_text}}</p>  
           
           {% elsif value_left >= 1 and value_left < 50 %}
            <p class="announcement-bar__message">{{unlocked_del_text}}</p>
           

           {% else %}
            <p class="announcement-bar__message">{{promote_text | replace:'(value)' , value_left_money}}</p>
           {% endif %}

基本上,这个想法是如果购物车总额在 $0-$99 之间,我将显示“promote_text”,如果在 $100-$149 之间,它将显示“Unlocked_free_del_text”(免费送货),然后在购物车中的 $150+它显示“unlocked_text”。

当前显示“promote_text”从 $0-$149 然后直接更改为“unlocked_text”并跳过“unlocked_del_text”的中间部分

我最好的假设是我错误地使用了 elsif 函数,但我已经在不破坏代码的情况下进行了尽可能多的调整,所以任何建议都将不胜感激!

【问题讨论】:

    标签: shopify liquid


    【解决方案1】:

    更新: 在通过开发商店检查和测试代码后,我发现您需要使用 divided_byvalue_left 的值来与标准化格式的值进行比较。

    所以你的代码需要更新这一行

    {% assign value_left = threshold | minus:cart.total_price | divided_by: 100%}
    

    因为 case 是 100 的倍数,要处理到购物车值,需要在测试到 if else 条件之前进行标准化。

    代码看起来不错,我不知道为什么它不能正常工作,你也可以用这种方式检查和尝试,我希望它会工作。否则,您需要将整个代码与架构一起发布,任何人都可以复制它开发存储并找到解决方案。

    {% if section.settings.free_shipping_announcement_bar %}    
         {% assign promote_text = section.settings.promote_free_shipping_text | escape %}
         {% assign unlocked_text = section.settings.unlocked_free_shipping_text | escape %}
         {% assign unlocked_del_text = section.settings.unlocked_free_delivery_text | escape %}  
         {% assign threshold = section.settings.free_shipping_threshold | times: 100 %}
         
    
         {% assign value_left = threshold | minus:cart.total_price | divided_by: 100%}
    
         {% assign value_left_money = value_left | money %}
         <div class="announcement-bar">       
            {% if value_left <= 0 %}
                 <p class="announcement-bar__message">{{unlocked_text}}</p>             
            {% elsif value_left >= 1 and value_left < 50 %}
                <p class="announcement-bar__message">{{unlocked_del_text}}</p>
            {% else %}            
                <p class="announcement-bar__message">{{promote_text | replace:'(value)' , value_left_money}}</p>
            {% endif %}
         </div>
       {% endif %}
    

    【讨论】:

    • 太棒了,它完美地工作了!非常感谢您的时间和贡献!
    【解决方案2】:

    感谢您的快速回复!我试用了您添加的 sn-p,但不幸遇到了同样的问题。这是我添加的用于影响我输入的代码部分的架构。如果您能够在这里发现一个简单的问题,请告诉我,否则,我将继续亲自进行故障排除,并希望找到解决方案或替代方法,以避免麻烦某人不得不复制整个代码来重新创建问题。

    {
        "type":"checkbox",
        "label":"enable free shipping bar",
        "id":"free_shipping_announcement_bar",
        "default":false
    },
    {
        "type":"text",
        "id":"promote_free_shipping_text",
        "label":"message to promote free shipping"
    },
    {
        "type":"text",
        "id":"unlocked_free_shipping_text",
        "label":"message for unlocked free shipping"
    },
    {
        "type":"text",
        "id":"unlocked_free_delivery_text",
        "label":"message for unlocked free delivery"
    },
    {
        "type":"range",
        "id":"free_shipping_threshold",
        "label":"threshold for free shipping",
        "min":0,
        "max":200,
        "step":5,
        "unit":"$",
        "default":150
    }
    

    【讨论】:

      猜你喜欢
      • 2018-08-17
      • 1970-01-01
      • 2017-11-19
      • 2015-08-26
      • 1970-01-01
      • 2017-02-05
      • 2021-09-04
      • 2012-06-06
      • 2021-05-01
      相关资源
      最近更新 更多