Shopify:全局变量数据类型

时间:2014-12-05 05:03:04

标签: global-variables shopify comparison-operators

我在Shopify中找到全局变量的数据类型时遇到了难以置信的困难。我的问题可能是范围问题,但他们仍然不应该告诉我数据类型。他们的技术支持说主题作者应该回答它,主题作者说Shopify应该回答它。恕我直言,他们中的任何一个都应该能够回答它。所以我非常感谢你能提供的任何智慧。

我的客户是批发商,他的订单不低于50.00美元。在总变量的变量中运行比较应该相当容易(cart.total_price | money_with_currency),但我的代码完全不成功。该代码还应允许零售商更改其订单并再次运行比较。我已经将所有可能的括号组合添加到变量和片段中,以防我出现语法错误。

        <div class="six columns cart-buttons">                
          {% if cart.total_price | money_with_currency < 50 %}
            <div style="font-weight: bold; color: #900; margin-bottom: 15px;">Your order must be at least $50.00</div>
          {% endif %}              


          {% if cart.total_price | money_with_currency > 50 %}
              <input class="button nice" type="submit" value="{{settings.checkout_text}}" name="checkout" />
                {% if additional_checkout_buttons %}
                  <em>or</em>
                  {{ content_for_additional_checkout_buttons }}
                {% endif %} 
            {% endif %}
           </div>   <!-- end cart buttons div -->

1 个答案:

答案 0 :(得分:1)

请参阅money filters上的Shopify文档。 money_with_currency过滤器可能会输出类似&#34; $ 1.45 CAD&#34;。也许试试money_without_currency,它将价格格式化为小数。

修改

money_without_currency看起来不起作用。以下代码会导致Liquid error: comparison of String with 50 failed

{% assign total_price = cart.total_price | money_without_currency %}
{% if total_price < 50 %} ... {% endif %} 

所以,你有两个选择。首先,您可以将money_without_currency的输出转换为如下数字:

{% assign total_price = cart.total_price | money_without_currency | times: 1 %}

或者,在没有过滤器的情况下与cart.total_price进行比较(添加2个零,因为cart.total_price没有小数位,所以如果没有使用过滤器格式化,则50.00美元为5000):

{% if cart.total_price < 5000 %} ... {% endif %}