简体   繁体   English

Shopify + CartJS用JS更新总价吗?

[英]Shopify + CartJS updating total price with JS?

I'm trying to update some data with AJAX on my Shopify theme, I'm also using the CartJS plugin. 我正在尝试使用有关Shopify主题的AJAX更新一些数据,我也在使用CartJS插件。 I have the counter working find but when I come to update the price it doesn't format correctly. 我找到了柜台,但是当我来更新价格时,它的格式不正确。 It does add all the correct numbers but misses out any currency symbol or decimal point. 它确实会添加所有正确的数字,但会漏掉任何货币符号或小数点。

Here's the code snippet: 这是代码片段:

<div id="mini-cart">
    <h2>Basket Updated <span class="btn-close">x</span></h2>
    <p><strong class="item-count">{{ cart.item_count }}</strong> item(s). Costing <strong class="total-price">{{ cart.total_price | money }}</strong></p>
</div>

<script>
    $(document).on('cart.requestComplete', function(event, cart) {

        $('.item-count').html(cart.item_count);
        $('.total-price').html(cart.total_price);
    });
</script>

I think it has something to do with {{ cart.total_price | money }} 我认为这与{{ cart.total_price | money }} {{ cart.total_price | money }} but whenever I add the | money {{ cart.total_price | money }}但每当我添加| money | money bit into the JS the whole thing breaks. | money投入了JS,整个事情破了。 Is there a way to format that in the script? 有没有办法在脚本中格式化它?

Thanks! 谢谢!

You should be sure to load also the option_selection.js library in your theme.liquid here is the string to add: 您应该确保还在主题中加载option_selection.jstheme.liquid是要添加的字符串:

{{ 'option_selection.js' | shopify_asset_url | script_tag }} 

Ref. 参考 https://cartjs.org/pages/guide#getting-started-setup https://cartjs.org/pages/guide#getting-started-setup

You need to add use data-cart-view to display values and products from your cart. 您需要添加使用数据购物车视图以显示购物车中的值和产品。 Simply use: 只需使用:

<span data-cart-view>
Costing <strong class="total-price">{{ cart.total_price | money }}</strong>
</span>

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

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