Wednesday, 15 June 2011

javascript - Add to cart function with product ID's -



javascript - Add to cart function with product ID's -

ive built custom product builder site, , stuck @ lastly step - adding products cart.

so on custom template file have code firing when 'add cart' button clicked:

$('#button-cart').bind('click', function() { $.ajax({ url: 'index.php?route=checkout/cart/add', type: 'post', data: $('i want set product id here, doesnt work'), datatype: 'json', success: function(json) { } });

i have product id saved javascript variable, need add together product cart. help great. thanks.

_____________ edit ______________

this recent code, function beingness fired when click add together cart button, locketid product id. success function beingness called neither of if statements (error or success) , beingness executed, , product isn't beingness added to cart.

is worth mentioning happening on category template file? there needs included might not be?

$('#button-cart').bind('click', function() { $.ajax({ url: 'index.php?route=checkout/cart/add', type: 'post', data: locketid, datatype: 'json', success: function(json) { console.log('success function called') if (json['error']) { console.log('error'); } if (json['success']) { console.log('success'); } } }); });

___________edit__________

so, i've taken different approach have in beingness called on add together cart button click, redirects product page rather add together product cart, ideas?

$('#button-cart-custom').bind('click', function() { var quantity = 1; var product_id = 12196; $.ajax({ url: 'index.php?route=checkout/cart/add', type: 'post', data: 'product_id=' + product_id + '&quantity=' + quantity, datatype: 'json', success: function(json) { $('.success, .warning, .attention, .information, .error').remove(); if (json['redirect']) { location = json['redirect']; } if (json['success']) { $('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.success').fadein('slow'); $('#cart-total').html(json['total']); $('html, body').animate({ scrolltop: 0 }, 'slow'); } } }); });

replace data: locketid

data:{'id':locketid}

and use

$_post['id'] info on server

javascript php ajax e-commerce opencart

No comments:

Post a Comment