$(function() { $('.button_acquista').click(function() { var strID_Prodotto = $(this).attr('name'); if ( strID_Prodotto != '' ) { var strID_Taglia = $(".taglia:checked").val(); var strID_Colore = $(".colore:checked").val(); $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/2020/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 : "" ), success: function(data) { if ( data.status == 'ok' ) { if ( ! parseInt( data.disponibile ) ) { swal("Ops...", "The product is not available", "error"); } else if ( parseInt( data.max ) > 0 ) { swal({ title: "Ok, the product is already in the cart!", text: "", type: "success", showCancelButton: true, cancelButtonText: "Stay where you are", confirmButtonText: "Go to the cart", closeOnConfirm: true }, function() { location.href = '/en/cart/'; }); } else { $('#cart-bar').removeClass('d-none'); $('#cart-bar a span').text( data.totale_prodotti ); swal({ title: "Ok, the product is in the cart!", text: "Stay where you are to continue shopping or go to the cart to complete your order.", type: "success", showCancelButton: true, cancelButtonText: "Stay where you are", confirmButtonText: "Go to the cart", closeOnConfirm: true }, function() { location.href = '/en/cart/'; }); } } else swal("Ops...", "LNG_AJAX_INSCARRELLO", "error"); }, error: function(data) { swal("Ops...", "Procedure uncompleted.", "error"); } }); /* ajax */ } }); });