2014-11-04 1 views
0

我想劃分{{item.price | money_without_currency}}減1.21。我在隱藏的輸入值中調用item.price。在shopify中劃分item.price

<input type="hidden" name="PRODUCT_PRICE_{{ forloop.index }}" value="{{ item.price | 
money_without_currency }}"> 
When I do the below, it shows the value as "100/1.21" as my test product is 100. Makes sense since HTML doesn't do math. 

<form name="addToFavorites" method="post" action="contoso.com"> 
<input type="hidden" name="PARTNER_KEY" value="34234234234234"> 
<input type="hidden" name="TOTAL_DOMESTIC_SHIPPING_CHARGE" value="0"> 
{% for item in cart.items %} 
<input type="hidden" name="PRODUCT_ID_{{ forloop.index }}" value="{{ item.sku }}"> 
<input type="hidden" name="PRODUCT_NAME_{{ forloop.index }}" value="{{ item.title }}"> 
<input type="hidden" name="PRODUCT_PRICE_{{ forloop.index }}" value="({{ item.price | 
money_without_currency }}/1.21)"> 
<input type="hidden" name="PRODUCT_Q_{{ forloop.index }}" value="{{ item.quantity }}"> 
<input type="hidden" name="PRODUCT_SHIPPING_{{ forloop.index }}" value=""> 
<input type="hidden" name="PRODUCT_CUSTOM_1_{{ forloop.index }}" value="{{ item.variant.title }}"> 
<input type="hidden" name="PRODUCT_CUSTOM_2_{{ forloop.index }}" value=""> 
<input type="hidden" name="PRODUCT_CUSTOM_3_{{ forloop.index }}" value=""> 
{% endfor %} 
</form> 

當我試着使用Javascript功能來播放,它仍然只是在方程100/1.21,而不是解決方案的帖子

<script> 
var withoutTax = {{ item.price | money_without_currency }}/1.21 
var euPrice = "name=\"PRODUCT_PRICE_{{ forloop.index }}\" value=\"+withoutTax+\"" 

window.onload = function() { 
     //when the document is finished loading, replace everything 
     //between the <a ...> </a> tags with the value of splitText 
    document.getElementById("euPrice").innerHTML=euPrice; 
} 

</script> 

<form name="addToFavorites" method="post" action="https://foo.com">; 
<input type="hidden" name="PARTNER_KEY" value="987979879879879"> 
<input type="hidden" name="TOTAL_DOMESTIC_SHIPPING_CHARGE" value="0"> 
    <input type="hidden" name="ORDER_CURRENCY" value="EUR"> 
{% for item in cart.items %} 
<input type="hidden" name="PRODUCT_ID_{{ forloop.index }}" value="{{ item.sku }}"> 
<input type="hidden" name="PRODUCT_NAME_{{ forloop.index }}" value="{{ item.title }}"> 
<input type="hidden" id="euPrice"> 
<input type="hidden" name="PRODUCT_Q_{{ forloop.index }}" value="{{ item.quantity }}"> 
<input type="hidden" name="PRODUCT_SHIPPING_{{ forloop.index }}" value=""> 
<input type="hidden" name="PRODUCT_CUSTOM_1_{{ forloop.index }}" value="{{ item.variant.title }}"> 
<input type="hidden" name="PRODUCT_CUSTOM_2_{{ forloop.index }}" value=""> 
<input type="hidden" name="PRODUCT_CUSTOM_3_{{ forloop.index }}" value=""> 
{% endfor %} 
</form> 

我的最終目標是採取$ 100個產品,21打折呢%,並插入 請在發佈信息之前將項目價格除以1.21。

回答

1

您可以使用divided_by數學過濾器:

{{ item.price | divided_by: 1.21 | money_without_currency }} 
+0

只是RTFM,看到這一點。是來回答我自己的問題,大聲笑。謝謝!!! – docwho 2014-11-04 21:53:58

+0

@docwho沒問題:) – 2014-11-04 23:11:37

1

使用JavaScript parseInt函數

var priceasnumber = parseInt({{ item.price | money_without_currency }}); 
var withoutTax = priceasnumber/1.21;