', {id:'modal-background'}).on('click',function(){}).appendTo('body');
modalbg.show();
});
});
// Main Add item to cart
function addItemCart(f) {
var frm = $(f);
var action = frm.closest('.prod-action');
var msg = action.find('.prod-input-msg');
action.find('.save-menu').hide();
action.find('.save-button-mask1').hide();
action.find('.save-button-mask2').hide();
msg.html('
Adding...').show();
var qty = Math.max(1,f.qty.value);
$.ajax({
cache: false,
url: f.action,
type: 'post',
dataType: 'json',
data: frm.serialize()+'&ajax=1&json=1',
success: function(r) {
var n = ' Item' + (r['added'] == 1 ? '' : 's');
if(r['error']) { // Error message
msg.html('
' + r['error'] + '.
View Cart');
return false;
} else if(r['added'] == 0) { // None in stock
msg.html('
Limited Qty.
View Cart');
cart_oos(r['items'],r['items']);
} else if(r['added'] < qty) { // Not enough in stock
msg.html('
' + r['added'] + ' Added.
View Cart');
cart_oos(r['items'],r['items']);
} else { // All availabe and added to cart
msg.html('
' + n + ' Added.
View Cart');
cart_success(r['items'],r['items']);
}
// Related Products
var sku = frm.find('[name=sku]').val();
var prod_id = frm.find('[name=product_id]').val();
$.ajax({
url: window.location.pathname,
type: 'post',
data: {m: 'relprod',sku:sku,qty:qty,added:r['added'],total:r['items'], ajax:1},
success: function(resp) {
if(resp.length) {
var e = $('#add-cart-related').html(resp).css({position:'absolute',visibility:'hidden'});
// var endht = e[0].offsetHeight;
e.css({position:'relative',visibility:'visible'});
// e.animate({height:endht},1000);
scrollTo('add-cart-related',1000);
if (window.quicklookSetup) window.quicklookSetup();
}
},
error: function(e){
console.log('Error');
console.log(e);
}
});
exponea.track('cart_update', {
action: 'add',
product_id: sku,
});
BrTrk.getTracker().logEvent('cart', 'click-add', {'prod_id': sku, 'sku':''});
// GA4
dataLayer.push(r['ga4']);
},
error: function() {
alert('addCart error');
}
});
return false;
}