function wishlist() { $(".product-wishlist").click(function(e) { if (e.preventDefault(), $(this).find("i").hasClass("fa-heart-o")) { var numWishlist = parseInt($("#main-navigation .wishlist_items_number").text()); $(".wishlist_items_number").text("").text(numWishlist + 1), $(this).parents(".product-single").length || ($(this).find("i").removeClass("fa-heart-o").addClass("fa-heart"), $(this).find("i").attr("title", "

Remove from Wishlist

").tooltip("dispose").tooltip("show")), $(this).parents(".product-single").length && $(this).fadeOut(300, function() { $(this).html(' Remove from Wishlist').fadeIn(300) }) } else { var numWishlist = parseInt($("#main-navigation .wishlist_items_number").text()); numWishlist > 0 && $(".wishlist_items_number").text("").text(numWishlist - 1), $(this).parents(".product-single").length || ($(this).find("i").removeClass("fa-heart").addClass("fa-heart-o"), $(this).find("i").attr("title", "

Add to Wishlist

").tooltip("dispose").tooltip("show")), $(this).parents(".product-single").length && $(this).fadeOut(300, function() { $(this).html(' Add from Wishlist').fadeIn(300) }) } }) } function getNum(val) { if (isNaN(val)) { return 0; } return val; } function addToCart() { $(".product, .product-single, .wishlist").on("click", ".add-to-cart, .view-cart", function(e) { // alert($(".cart_items_number").text()); var oldNum=getNum(parseInt($(".cart_items_number").text())); // alert("vecchio valore: "+oldNum); if (oldNum<1) { oldNum=0; } numCart=getNum(parseInt(oldNum+1)); // alert("nuovo valore: "+numCart); // alert(numCart); $(this).hasClass("view-cart") && (window.location.href = "https://www.cesaregatti.com//cart.php"), e.preventDefault(), $(this).fadeOut(300, function() { $(".products-list").length ? ($(this).html("View Cart").removeClass("add-to-cart").addClass("view-cart").attr("href", "cart").fadeIn(300), $(this).find("i").attr("title", "

Add to Wishlist

").tooltip("dispose").tooltip("show")) : $(this).parents(".product-single").length ? $(this).html('Carrello').removeClass("add-to-cart").removeClass("btn-primary").addClass("view-cart").addClass("btn-dark").attr("href", "https://www.cesaregatti.com//cart.php").fadeIn(300) : $(this).parents(".product-info").length ? ($(this).html("View Cart").removeClass("add-to-cart").addClass("view-cart").attr("href", "https://www.cesaregatti.com//cart.php").fadeIn(300), $(this).attr("data-original-title", "

View Cart

").tooltip("dispose").tooltip("show")) : $(this).html('View Cart').removeClass("add-to-cart").removeClass("btn-primary").addClass("view-cart btn-dark").attr("href", "https://www.cesaregatti.com//cart.php").fadeIn(300), $(".cart_items_number").text(numCart) }) }), $("body").on("click", ".add-to-cart", function() { var magnificPopup = $.magnificPopup.instance; if (magnificPopup.close(), toastr.options = { positionClass: "toast-bottom-right" }, $(".wishlist").length) { // alert("1"); } else if ($(this).parents(".product-single").length) { var itemName = $("#productNameLocalized").text(), categoryName = $("#categoryNameLocalized").text(), itemImg = $(this).parents(".product-single").find("img").attr("src"), itemPrice = $("#priceLocalized").text(); var itemID = $(this).attr("rel"); $.post( "https://www.cesaregatti.com/orangeCMS/ajax/cart.php", { "op": "add", "id_prodotto": itemID, "qty_prodotto": "1", "img_prodotto": itemImg, "prezzo_prodotto": itemPrice, "nome_prodotto": itemName, "categoria_prodotto": categoryName }).done(function( newID ) { toastr.info('
cart image
' + itemName + ' - '+ categoryName + '
added to cart
€ ' + itemPrice + '
') }); // alert("2"); } else { toastr.info('
jacket 1
Item added to your cart
$59.95
') // alert("4"); } }) } function removeFromCart() { $(".product-remove a").on("click", function(e) { e.preventDefault(); var numCart = parseInt($("#main-navigation .cart_items_number").text()); var itemName = $(this).parents(".cart-item").find(".product-name").text(), itemImg = $(this).parents(".cart-item").find("img").attr("src"), itemPrice = $(this).parents(".cart-item").find(".product-price").text(); // alert("rimuovo #riga"+$(this).attr("rel")); $.post( "https://www.cesaregatti.com/orangeCMS/ajax/cart.php", { "op": "remove", "id_prodotto": $(this).attr("rel") }).done(function( data ) { var res = $.parseJSON(data); // alert("res: "+res); if(res > 0 ){ // alert("rimuovo #riga"+res); if ($(this).parents("#cart-quickview").length > 0) { var itemQuantity = $(this).parents(".cart-item").find(".product-qty").data("qty"); console.log(itemQuantity), $(".cart_items_number").text(numCart - itemQuantity), 1 == $(this).parents("#cart-quickview").find(".cart-item").length && ($("#cart-quickview .table-cart, #cart-quickview .cart-total, #cart-quickview .btn").fadeOut(), $("#cart-quickview").append('

Your cart is empty

')) } else $(".cart_items_number").text(numCart - $(this).parents(".cart-item").find(".quantity input").val()); // alert("rimuovo #riga"+res); // alert("rimuovo : #riga"+res); $("#riga"+res).fadeOut(300, function() { $(".tooltip").remove(), $(this).remove(), calculTotal() }), toastr.options = { positionClass: "toast-bottom-right" }, toastr.info('
removed item
' + itemName + ' removed
' + itemPrice + "
") } }); }) } function updateAmountCart() { var numCart = 0; $(".quantity input").each(function() { numCart += parseFloat($(this).val()); }), $(".cart-item").on("click", ".quantity .plus", function() { var idProdotto=$(this).parents(".cart-item").attr("rel"); var newQty=parseInt($(this).parents(".cart-item").find(".product-qty input").val()) + 1; //alert("newQty "+newQty); var numCart = parseInt($("#main-navigation .cart_items_number").text()); $.post( "https://www.cesaregatti.com/orangeCMS/ajax/cart.php", { "op": "plus", "id_prodotto": idProdotto, "newQty": newQty }).done(function( data ) { $(".cart_items_number").text(numCart + 1); var itemPrice = $("#riga"+idProdotto).find(".product-price span").text(); var currentVal = parseInt($("#riga"+idProdotto).find("input").val()); var itemTotal = itemPrice * currentVal; // alert("itemPrice "+itemPrice+" - currentVal "+currentVal+" - itemTotal "+itemTotal); $("#riga"+idProdotto).find(".product-total").html("€ " + itemTotal.toFixed(0) + ""), calculTotal() }); }), $(".cart-item").on("click", ".quantity .minus", function() { var idProdotto=$(this).parents(".cart-item").attr("rel"); var newQty=parseInt($(this).parents(".cart-item").find(".product-qty input").val()) - 1; $.post( "https://www.cesaregatti.com/orangeCMS/ajax/cart.php", { "op": "minus", "id_prodotto": idProdotto, "newQty": newQty }).done(function( data ) { var itemPrice = $("#riga"+idProdotto).find(".product-price span").text(); var currentVal = parseInt($("#riga"+idProdotto).find("input").val()); var itemTotal = itemPrice * currentVal; if (currentVal > 0) { var numCart = parseInt($("#main-navigation .cart_items_number").text()); numCart > 0 && $(".cart_items_number").text("").text(numCart - 1), $("#riga"+idProdotto).find(".product-total").html("€ " + itemTotal.toFixed(0) + ""), calculTotal() } }); }) } function calculTotal() { var subtotal = 0, total = 0, shippingCost = parseFloat($("input[name=shipping-cost]:checked").val()); $(".product-total span").each(function() { subtotal += parseFloat($(this).text()) }), total = subtotal + shippingCost, $(".cart-subtotal-val span").text(total.toFixed(0)), $(".cart-total-val span").text(total.toFixed(0)) } function shipping() { $("input[name=shipping-cost]").click(function() { var subtotal = 0, total = 0, shippingCost = parseFloat($("input[name=shipping-cost]:checked").val()); $(".checkout-form").length ? subtotal = parseFloat($(".cart-subtotal-val span").text()) : $(".product-total span").each(function() { subtotal += parseFloat($(this).text()) }), total = subtotal + shippingCost, $(".cart-total-val span").text(total.toFixed(0)) }) } function productVariable() { if ($(".select-color").length || $(".select-size").length) { $(".quantity-cart, #clear-selection").hide(); var colorData = sizeData = "null"; $(".select-color").on("change", function() { $("#clear-selection").fadeIn(), colorData = $(this).val(), void 0 !== colorData && ($("#clear-selection").show(), "orange" === colorData && ($("#product-slider").flexslider(0), $("#product-slider-thumbnails").flexslider(0)), "blue" === colorData && ($("#product-slider").flexslider(3), $("#product-slider-thumbnails").flexslider(3)), "brown" === colorData && ($("#product-slider").flexslider(6), $("#product-slider-thumbnails").flexslider(6))), "null" !== colorData && "null" !== sizeData ? $(".quantity-cart").fadeIn() : $(".quantity-cart").fadeOut() }), $(".select-size").on("change", function() { $("#clear-selection").fadeIn(), sizeData = $(this).val(), "null" !== colorData && "null" !== sizeData ? $(".quantity-cart").fadeIn() : $(".quantity-cart").fadeOut() }) } $("#clear-selection").click(function(e) { e.preventDefault(), $(".select-color").val("choose").trigger("change"), $(".select-size").val("choose").trigger("change"), $("#clear-selection").fadeOut() }) } function extendedProduct() { $(".product-single, .extended-product-img-wrapper").css("min-height", ""), $(".extended-product:not(.extended-third)").each(function() { var extendedProduct = $(this); extendedImg = extendedProduct.find(".extended-product-img"), extendedImgHeight = extendedImg.height(), extendedDesc = extendedProduct.find(".extended-product-desc"), extendedDescHeight = extendedDesc.height(), extendedImgHeight > extendedDescHeight ? extendedProduct.hasClass("extended-product-first") || extendedProduct.hasClass("extended-product-last") ? extendedProduct.find(".product-single").css("min-height", extendedImgHeight - 30) : extendedProduct.find(".product-single").css("min-height", extendedImgHeight - 60) : extendedProduct.hasClass("extended-alone") ? extendedImg.find(".extended-product-img-wrapper").css("min-height", extendedDescHeight - 60) : extendedImg.find(".extended-product-img-wrapper").css("min-height", extendedDescHeight) }), $(".extended-product.extended-third").each(function() { var extendedProduct = $(this); extendedProductHeight = extendedProduct.height(), extendedProduct.find(".extended-product-desc .product-single, .extended-product-img-wrapper").css("min-height", extendedProductHeight) }) }