$(document).ready(function() { $('#add_pack_right').on('click', function(e){ addCmsPackToCart(".checkbox_add_right", ".pack_left"); }); $('#add_pack_bottom').on('click', function(e){ addCmsPackToCart(".checkbox_add_bottom", ".pack_bottom"); }); updateInfo(".checkbox_add_right", ".pack_left"); $('.checkbox_add_right').on('click', function(e) { updateInfo(".checkbox_add_right", ".pack_left"); }); $('.quantity_right').on('focusout', function(e) { updateInfo(".checkbox_add_right", ".pack_left"); }); updateInfo(".checkbox_add_bottom", ".pack_bottom"); $('.checkbox_add_bottom').on('click', function(e) { updateInfo(".checkbox_add_bottom", ".pack_bottom"); }); $('.quantity_bottom').on('focusout', function(e) { updateInfo(".checkbox_add_bottom", ".pack_bottom"); }); $('#layer_cart_pack .cross, .layer_cart_overlay_pack, #layer_cart_pack .continue.link').on('click',function(){ if($('#layer_cart_pack').hasClass('open') == true) $('#layer_cart_pack').removeClass('open'); $('.layer_cart_overlay_pack').hide(); }); }); function updateInfo(checkboxes, pack) { var total = 0; $(checkboxes).each(function( index ) { if ($(this).is(':checked')) { var idProduct = $(this).attr('name'); var quantity = $(pack+' input[name="quantity_'+idProduct+'"]').val(); var price = $(pack+' input[name="quantity_'+idProduct+'"]').data('product-price-nf'); total += (parseFloat(quantity)*parseFloat(price)); } }); $(pack).find('.price_info').children('.price').html(parseFloat(total).toFixed(2) + " €"); } function addCmsPackToCart(checkboxes, pack) { var addProducts = []; var html = ""; var quantity_add = 0; var n = parseInt($(window).scrollTop() + 20) + 'px'; $('#layer_cart_pack').css({'top': n}); $(checkboxes).each(function( index ) { if ($(this).is(':checked')) { var idProduct = $(this).attr('name'); var quantity = $(pack+' input[name="quantity_'+idProduct+'"]').val(); var name = $(pack+' input[name="quantity_'+idProduct+'"]').data('product-name'); var img = $(pack+' input[name="quantity_'+idProduct+'"]').data('product-img'); var price = $(pack+' input[name="quantity_'+idProduct+'"]').data('product-price'); if (result = ajaxCart.add(idProduct, null, false, '', quantity, false, true)) { addProducts.push(idProduct); } if(quantity > 0) { html += "
"+name+"
"+price+"
x "+quantity+"