Shopify.onItemAdded更新#cart和cart.item.count [英] Shopify.onItemAdded update #cart and cart.item.count

查看:293
本文介绍了Shopify.onItemAdded更新#cart和cart.item.count的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Shopify一个ajaxed购物车。我所做的产品页面添加项目到购物车无刷新或去购物车页面。要查看购物车,您可以点击输入或链接.cart秀,所以我说这添加到购物车输入:

I'm trying to make a ajaxed shopping cart in Shopify. I have made the product page add an item to cart without refreshing or going to the cart page. To see cart, you can click on an input or link with .cart-show, so I added this to the 'add to cart' input:

<input style="margin-top: 40px; width: 50%;" type="submit" value="Add to cart" class="button cart-show" onclick=" Shopify.addItemFromForm('add-item-form'); return false" />

是什么一样,只是添加项目到购物车,并显示车DIV #menu。当然,购物车,当一个新项目添加没有更新,问题是:我该怎么办呢? 我怎样才能让车股利#cart更新输入每次点击?我如何更新在div#车与总项目的cart.item_count当一个新产品添加?我用了一天多摸不着头脑,仍然没有得到任何地方。我甚至试着问对Shopify论坛,但它仅仅是死了,也没有帮助才能在那边。

What that does, is simply add the item to cart and display the cart div #menu. Of course cart doesn't get updated when a new item is added, and the question is: how can I do this? How can I make the cart div #cart update each time the input is clicked? And how do I update the cart.item_count in the div #cart-total-items when a new product is added? I've used more than a day to figure this out and still haven't gotten anywhere. I have even tried asking on the Shopify Forum, but it is simply dead and no help to get over there.

在'Shopify.onItemAdded剧本时,增加了一个新的产品如下:

The 'Shopify.onItemAdded' script for when an new item is added is as follows:

 Shopify.onItemAdded = function(line_item) {
    Shopify.getCart();

    refresh #menu script here

    refresh cart.item.count script  in theme.liquid could be something like this, but it doesn't work: 

    $('#cart-total-items').update(cart.item_count);
  };

cart.item_count

cart.item_count

<span style="" id="cart-total-items"><a class="cart-show">Bag ({{ cart.item_count }})</a></span>

任何想法?

推荐答案

这可能不是正是你需要的,但它可能会有所帮助。我已经制定并实施一个Ajax购物车在shopify网站我开发。我使用jQuery和放大器; JSON做这种类型的东西,这是我做的:

This might not be exactly what you need but it may help. I have made and implemented an ajax cart on a shopify site I develop for. I use jquery & JSON to do this type of stuff and here's what I do:

jQuery.getJSON('/cart.js', function (cart, textStatus) {
  //the cart info is in the callback. the item_count is available as part of the callback
  //below I set my cartcount div with the current cart item_count
  var carttext=cart.item_count;
  jQuery("#cartcount").text(carttext);
});

这篇关于Shopify.onItemAdded更新#cart和cart.item.count的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆