2014-12-05 117 views
0

我在Shopify中找到全局變量的數據類型的難度令人難以置信。我的問題可能是一個範圍問題,但它們應該不難告訴我一種數據類型。他們的技術支持說主題作家應該回答它,主題作者說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

請參閱money filters上的Shopify文檔。 money_with_currency過濾器可能會輸出類似「$ 1.45 CAD」的內容。也許試試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 %} 

所以,你有2個選項。首先,你可以的money_without_currency輸出轉換爲數字是這樣的:

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

或者,比較反對cart.total_price無過濾器(加2個0,因爲cart.total_price沒有一個小數位,所以$ 50.00是5000,如果沒有格式化用錢過濾器):

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

令人難以置信! {%assign total_price = cart.total_price | money_without_currency |次數:1%}在嘗試其他組合後經受了數小時的挫折。 - 我認爲全局變量可以像其他變量一樣使用,但似乎Shopify變量還包含一些必須運行的處理,因此將結果賦給局部變量。 - 我相信Shopify是用Ruby編寫的,所以我想知道這個結構是Ruby還是Shopify? – Nora 2014-12-05 15:37:41