$(function() { $('.button_acquista').click(function() { var strID_Prodotto = $(this).attr('name'); if ( strID_Prodotto != '' ) { var strSKU = String( $(this).data('sku') != undefined ? $(this).data('sku') : '' ); var strID_Taglia = String( $("#cmbVariantiTaglie").val() != undefined ? $("#cmbVariantiTaglie").val() : '' ); var strID_Colore = String( $("#cmbVariantiColori").val() != undefined ? $("#cmbVariantiColori").val() : '' ); var strID_Scatola = $(".scatola:checked").data('idscatola'); var strID_Materiali = String( $("#cmbVariantiMateriali").val() != undefined ? $("#cmbVariantiMateriali").val() : '' ); var strID_Spessore = String( $("#cmbVariantiSpessori").val() != undefined ? $("#cmbVariantiSpessori").val() : '' ); $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/setCarrello.php", data: "action=setCarrello&pstrID_Prodotto=" + strID_Prodotto + "&pintQuantita=" + $("#fp_quantita").val() + "&pstrCarrelloTipo=" + $("#fp_carrello_tipo").val() + "&pstrLangCurrent=" + $("#fp_lang_current").val() + ( strID_Taglia != undefined && strID_Taglia != "" ? "&pstrID_Taglia=" + strID_Taglia : "" ) + ( strID_Colore != undefined && strID_Colore != "" ? "&pstrID_Colore=" + strID_Colore : "" ) + ( strID_Scatola != undefined && strID_Scatola != "" ? "&pstrID_Scatola=" + strID_Scatola : "" ) + ( strID_Materiali != undefined && strID_Materiali != "" ? "&pstrID_Materiali=" + strID_Materiali : "" ) + ( strID_Spessore != undefined && strID_Spessore != "" ? "&pstrID_Spessore=" + strID_Spessore : "" ), success: function(data) { if ( data.status == 'ok' ) { if ( ! parseInt( data.disponibile ) ) { swal("Ops...", "Il prodotto non è disponibile", "error"); } else if ( parseInt( data.max ) > 0 ) { swal({ title: "Ok, il prodotto è già nel carrello!", text: "", type: "success", showCancelButton: true, cancelButtonText: "Resta dove sei", confirmButtonText: "Vai al Carrello", closeOnConfirm: true }, function() { location.href = '/carrello/'; }); } else { $('.cart-link').removeClass('d-none'); $('.cart-link span').text( data.totale_prodotti ); $('#cart-link').removeClass('d-none').addClass('d-inline'); swal({ title: "Ok, il prodotto è nel carrello!", text: "Resta dove sei per continuare gli acquisti oppure vai al carrello per completare il tuo ordine", type: "success", showCancelButton: true, cancelButtonText: "Resta dove sei", confirmButtonText: "Vai al Carrello", closeOnConfirm: true }, function() { location.href = '/carrello/'; }); } } else swal("Ops...", "Inserimento nel carrello non riuscito.", "error"); }, error: function(data) { swal("Ops...", "Procedura non completata.", "error"); } }); /* ajax */ } }); });