Reputation: 7
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?
Upvotes: 0
Views: 2842
Reputation: 2058
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');});
Upvotes: 0