简体   繁体   English

Shopify 价格问题

[英]Shopify Price Issue

I am struggling here.我在这里挣扎。 When I comment out the var priceRounded = {{ product.price |当我注释掉 var priceRounded = {{ product.price | money_without_trailing_zeros }}; money_without_trailing_zeros }}; line the calculations work.行计算工作。 When I don't comment it out then nothing happens.当我不评论它时,什么也不会发生。 I'm trying to render out the price without the zeros.我试图在没有零的情况下呈现价格。 So if the product price is £20.00 then Shopify for some reason thinks it's £2000.因此,如果产品价格为 20.00 英镑,则 Shopify 出于某种原因认为它是 2000 英镑。 Therefor I need to remove the trailing zeros as described in Shopify's documents .因此,我需要按照Shopify 文档中的描述删除尾随零。

Price {{ product.price | money_without_trailing_zeros }}<br />
<label for="meters-required">Number of M2</label><br />
<input type="number" id="meters-required" name="properties[meters required]" required minlength="1" maxlength="8" size="10"><br />    

Total Packs: <span id="output_totalPacks"></span><br />
Total Price: <span id="output_totalPrice"></span><br />
Price per Pack: <span id="output_pricePerPack"></span><br />
Price per Meter: <span id="output_pricePerMeter"></span><br />
Pack Size: <span id="output_PackSize"></span><br />


<script>

 var meters_req = document.querySelector("#meters-required"); var output_totalPacks = document.querySelector("#output_totalPacks"); var output_totalPrice = document.querySelector("#output_totalPrice"); var output_pricePerPack = document.querySelector("#output_pricePerPack"); const packSize = {{ packSize }}; const price = {{ product.price }}; //var priceRounded = {{ product.price | money_without_trailing_zeros }}; function woolCalc(){ var meters_required = document.getElementById("meters-required").value; var calc_TotalPrice = price * meters_required; var calc_TotalPacks = meters_required / packSize; var calc_PackPrice = price * packSize; output_totalPacks.innerHTML = calc_TotalPacks; document.getElementById("output_PackSize").innerHTML = packSize; document.getElementById("output_pricePerPack").innerHTML = calc_PackPrice; document.getElementById("output_totalPrice").innerHTML = calc_TotalPrice; } meters_req.addEventListener("input", woolCalc);
 Price {{ product.price | money_without_trailing_zeros }}<br /> Pack Size: {{ packSize }}<br /> Title: {{ priceRounded }};<br /> <label for="meters-required">Number of M2</label><br /> <input type="number" id="meters-required" name="properties[meters required]" required minlength="1" maxlength="8" size="10"><br /> Total Packs: <span id="output_totalPacks"></span><br /> Total Price: <span id="output_totalPrice"></span><br /> Price per Pack: <span id="output_pricePerPack"></span><br /> Price per Meter: <span id="output_pricePerMeter"></span><br /> Pack Size: <span id="output_PackSize"></span><br />

Any thoughts on what could be causing it?关于可能导致它的任何想法? Or how to make the function calculate the price without thinking it is 100 x the actual price?或者如何让 function 在不认为它是实际价格的 100 x 的情况下计算价格?

Shopify deals with money as a type of Integer. A product priced as 9.99 is dealt with as 999 at Shopify. That way, when doing math, there is no 'precision' lost. Shopify 将货币作为 Integer 的一种进行处理。定价为 9.99 的产品在 Shopify 中处理为 999。这样,在进行数学运算时,不会丢失“精度”。 You have the obligation of converting from the integer to the decimal using filters.您有义务使用过滤器将 integer 转换为小数。

So if you see 2000 and not 20.00 as you'd expect, it is because you are not converting the money with a filter.因此,如果您看到的是 2000 而不是您预期的 20.00,那是因为您没有使用过滤器转换货币。 There are both Liquid and JS filters for this.为此,有 Liquid 和 JS 过滤器。 So 'nothing' is causing it, it is a natural thing in Shopify.所以“没有”是造成它的原因,这是 Shopify 中的自然现象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM