简体   繁体   English

使用 Cart.js 和 Rivets.js 添加/删除购物车项目

[英]Adding/Removing Cart Items Using Cart.js and Rivets.js

I'm using cart.js on my Shopify store but can't get the increase/decrease quantity or remove features to work.我在 Shopify 商店中使用了 cart.js,但无法增加/减少数量或删除功能。 Everything else is working properly so I'm not sure what I'm doing wrong.其他一切都正常工作,所以我不确定我做错了什么。

I have the following code added just before the closing </body> tag on theme.liquid .我在theme.liquid的关闭</body>标记之前添加了以下代码。

{{ 'rivets-cart.min.js' | asset_url | script_tag }}

<script type="text/javascript">
    jQuery(function() {
        CartJS.init({{ cart | json }}, {
            "dataAPI": false,
            "requestBodyClass": "loading"
        });
    });
</script>

Below is the code I have in header.liquid ... I've also tested this on product-template.liquid and still get the same results.下面是我在header.liquid 中的代码……我也在 product-template.liquid 上测试过,仍然得到相同的结果。

<div class="cart-product-wrap" rv-each-item="cart.items">

  <div class="cart-quantity">
    <a href="#" rv-data-cart-update="index | plus 1" rv-data-cart-quantity="item.quantity | plus 1">+</a>
    <div rv-text="item.quantity"></div>
    <a href="#" rv-data-cart-update="index | plus 1" rv-data-cart-quantity="item.quantity | minus 1">-</a>
  </div>

  <div class="cart-image"><img rv-src="item.image | productImageSize 'small'" src=""></div>

  <div class="cart-title-price">
    <div class="cart-title" rv-text="item.title"></div>
    <div class="cart-price" rv-html="item.price | money Currency.currentCurrency"></div>
    <div class="cart-remove"><a href="#" rv-data-cart-remove="index | plus 1">Remove</a></div>
  </div>

</div>

I've followed the guide on https://cartjs-dev.myshopify.com/pages/guide and don't see any difference from the working example.我遵循了https://cartjs-dev.myshopify.com/pages/guide上的指南,并没有看到与工作示例有任何区别。

Does anyone have any idea what I'm doing wrong or how I can get this working?有谁知道我做错了什么或者我如何让它工作?

Any help would be greatly appreciated!任何帮助将不胜感激!

In case anyone was wondering, I got this to work by changing the script to...如果有人想知道,我通过将脚本更改为...

<script type="text/javascript">
    jQuery(function() {
        CartJS.init({{ cart | json }}, {
        });
    });
</script>

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

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