簡體   English   中英

在shopify中划分item.price

[英]Dividing item.price in shopify

我想划分{{item.price | money_without_currency}}之前的1.21。 我正在以隱藏的輸入值調用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,以獲取幫助。

使用Javascript parseInt

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

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM