javascript - 在shopify中划分item.price

标签 javascript forms shopify

我想除以 {{ item.price |没有货币的货币 }} 提高 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。

最佳答案

您可以使用divided_by数学过滤器:

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

关于javascript - 在shopify中划分item.price,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26737527/

相关文章:

javascript - 当窗口小于 ~650px 时,Owl Carousel 不居中

javascript - 突出显示 react native ListView 中的顶行

javascript - Sails.js 的模型是否具有像 Django 中的模型那样的反向引用功能?

zend-framework - Zend 框架 : Conditional validation

php - 如果没有表单类,我无法在 symfony2 中上传文件

css - SASS插值错误

javascript - 如何运行 Php 脚本使用 cronjob 静默包含 javascript

python - 使用 Python API 创建产品时未收到来自 Shopify 的响应

css - Shopify 应用集成主题问题

asp.net-mvc - 表单发布场景和 MVC 中的复杂模型更新