79 lines
2.9 KiB
JavaScript
79 lines
2.9 KiB
JavaScript
$(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;
|
|
$(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.addMultiple(idProduct, null, quantity)) {
|
|
addProducts.push(idProduct);
|
|
}
|
|
if(quantity > 0) {
|
|
html += "<div class='col-xs-12 product-info-container'><div class='product-image-container col-xs-2 col-xxs-12'><img src='"+img+"' class='img-responsive' ></div><div class='product-box col-xs-10 col-xxs-12'><p class='product-name'>"+name+"</p><p class='prices'><span class='product-price'>"+price+"</span></p><p class='product-attributes col-xs-2'>x <span class='nb_quantity'>"+quantity+"</span></p></div></div></div>";
|
|
quantity_add += + parseInt(quantity);
|
|
}
|
|
}
|
|
});
|
|
|
|
setTimeout(function() {
|
|
ajaxCart.updateInfoCart(quantity_add);
|
|
$('#layer_cart_pack #product-info').html(html);
|
|
if($('#layer_cart_pack').hasClass('open') == false)
|
|
$('#layer_cart_pack').addClass('open');
|
|
$('.layer_cart_overlay_pack').show();
|
|
}, 1500);
|
|
}
|