Skip to content

Instantly share code, notes, and snippets.

@j7u7l7s
Created May 29, 2018 20:54
Show Gist options
  • Save j7u7l7s/c5a0e271b8e5386448a889bad7c2b9a8 to your computer and use it in GitHub Desktop.
Save j7u7l7s/c5a0e271b8e5386448a889bad7c2b9a8 to your computer and use it in GitHub Desktop.
$(document).on('click','.productId', function(e){
var qty = 1;
var id = $(this).data('variant');
addItem=function(qty,id,callback) {
var params = {quantity:qty,id:id};
$.ajax({
type: 'POST',
url: '/cart/add.js',
dataType: 'json',
data: params,
success: function(){
$.getJSON('/cart.js', function(cart) {
var new_count = cart.item_count ;
$('.site-header-cart--count ').attr('data-header-cart-count', new_count);
});
},
error: function(){}
});
}
addItem(qty,id,function(){
console.log('done');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment