0
votes

I have a Shopify site with a slide out cart that shows on every page.

To do this I have copied the content from the cart page and added it to a slide toggle in the main template.

Because of this, when an item is added to the cart, it does not show in the slide out cart.

Is there a way to refresh the page whenever a product is added to the cart, so that it appears in the cart?

1
why don't you use the ajax cart from shopify.miglio
Thanks - but I can't find any documentation on setting this up if you can help me find that. Is it included in any of the default themes?Matt Kempster
@miglio please see above, thanks!Matt Kempster

1 Answers

0
votes

i have used this Shopify's Ajax API for get,insert,update,delete the cart

// Example to add product with properties
addItem=function(product,callback) {
  var params = {quantity:product.qty,id:product.id};
  if(product.properties != false){
      params.properties = product.properties;
  }
  $.ajax({
    type: 'POST',
    url: '/cart/add.js',
    dataType: 'json',
    data: params,
    success: function(){
        if(typeof callback === 'function'){
            callback();
        }
    },
    error: function(){}
  });
} 
//
var product = {qty:1,id:541926339,properties:{size:2}}
addItem(product,function(){ alert('success');});