$(function() { $('.button_acquista').click(function() { var strID_Prodotto = String( $(this).attr('name') != undefined ? $(this).attr('name') : '' ); if ( strID_Prodotto ) { var strSKU = String( $(this).data('sku') != undefined ? $(this).data('sku') : '' ); var strID_Forma = String( $("#cmbVariantiForme").val() != undefined ? $("#cmbVariantiForme").val() : '' ); var strID_Dimensioni = String( $("#cmbVariantiDimensioni").val() != undefined ? $("#cmbVariantiDimensioni").val() : '' ); var strID_Decoro = String( $("#cmbVariantiDecori").val() != undefined ? $("#cmbVariantiDecori").val() : '' ); var strID_ColoreDecoro = String( $("#cmbVariantiColoriDecori").val() != undefined ? $("#cmbVariantiColoriDecori").val() : '' ); var strID_Lista = String( $("#fp_id_lista").val() != undefined ? $("#fp_id_lista").val() : '' ); var carrelloTipo = String( $("#fp_carrello_tipo").val() != undefined ? $("#fp_carrello_tipo").val() : '' ); var langCurrent = String( $("#fp_lang_current").val() != undefined ? $("#fp_lang_current").val() : '' ); var intQuantita = parseInt( $('#intQuantita').val() ); if ( ! isPositive( intQuantita ) ) intQuantita = 1; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/setCarrello.php", data: "action=setCarrello" + "&pstrID_Prodotto=" + strID_Prodotto + "&pstrCarrelloTipo=" + carrelloTipo + "&pstrLangCurrent=" + langCurrent + "&pstrID_Forma=" + strID_Forma + "&pstrID_Dimensioni=" + strID_Dimensioni + "&pstrID_Decoro=" + strID_Decoro + "&pstrID_ColoreDecoro=" + strID_ColoreDecoro + "&pstrID_Lista=" + strID_Lista + "&pintQuantita=" + intQuantita, success: function(data) { if ( data.status == 'ok' ) { if ( ! parseInt( data.disponibile ) ) { swal("Ops...", "El producto no esta disponible", "error"); } else if ( parseInt( data.max ) > 0 ) { swal({ title: "Ok, el producto ya está en el carrito!", text: "", type: "success", showCancelButton: true, cancelButtonText: "Continuar comprando", confirmButtonText: "Ir al carrito", closeOnConfirm: true }, function() { location.href = '/es/carrito/'; }); } else { fbq('track', 'AddToCart', { value: parseFloat( data.cart_prezzo ), currency: 'EUR', content_type: 'product', content_ids: [strSKU], content_name: String( data.cart_nome ), content_category: String( data.cart_categoria ) }); if ( parseInt( data.carrello_start ) > 0 ) fbq('track', 'InitiateCheckout'); $('.cart-span').removeClass('hide'); $('.cart-span').text( data.totale_prodotti ); swal({ title: "Ok, el producto está en el carrito!", text: "Quédese donde está para continuar comprando o vaya al carrito para completar su pedido.", type: "success", showCancelButton: true, cancelButtonText: "Continuar comprando", confirmButtonText: "Ir al carrito", closeOnConfirm: true }, function() { location.href = '/es/carrito/'; }); } } else swal("Ops...", "La inclusión en la cesta falló.", "error"); }, error: function(data) { swal("Ops...", "Procedimiento no se ha completado.", "error"); } }); /* ajax */ } }); }); function isPositive (number) { if ( number > 0 ) { return true; } if (number < 0) { return false; } if ( 1 / number === Number.POSITIVE_INFINITY ) { return true; } return false; }