If you want to enable Add to Cart function on a button, you simply follow these.
Code for button below
<input type=“button” value="" onclick=“addTOCART(’’);” />
Code for JavaScript effect below
function addTOCART(product_id, quantity) { quantity = typeof(quantity) != ‘undefined’ ? quantity : 1;
$.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(’’);
$(’.success’).fadeIn(‘slow’); try { $(’#cart-total’).html(json[’total’]); } catch(err) { console.log(err.message()); }
$(‘html, body’).animate({ scrollTop: 0 }, ‘slow’);
$(".heading").animate({backgroundColor: “#FFFFFF”}, ‘slow’);
$(".cart_arrow").attr(“style”, “display: block;”);
$(".heading").animate({backgroundColor: “#585858”}, ‘slow’);
} } }); }
