$( function() { $("#completa-ordine").click(function() { if ( parseInt( $('#ordine_acquistabile').val() ) > 0 ) { if ( fCheckObbligatori() ) fSaveData(); } else if ( $("#cmbNazione").val() == 'IT' && $.trim( $('#cmbProvincia').val() ) == '' ) swal( "Warning!", "choose province", "error" ); else swal( "Warning!", "The order is not available.", "error" ); }); // azienda $('#sono_azienda').change(function() { if ( $(this).prop('checked') ) { // AZIENDA $('#dati_fatturazione').removeClass('d-none'); } else { // PRIVATO $('#dati_fatturazione').addClass('d-none'); } }); $('#txtEmail').change(function() { $('.loader-txtEmail').removeClass('d-none'); $('#lbltxtEmail-login').addClass('d-none'); $('#lbltxtEmail, #lbltxtEmail-login').html(''); $(this).removeClass('is-invalid').removeClass('is-valid'); if ( $.trim( $(this).val() ) == "" ) { // ERRORE : email obbligatoria $(this).removeClass('is-valid').addClass('is-invalid'); //$('#lbltxtEmail').html( fHTMLErrore( "Required" ) ); } else if (!(/(.+)@(.+){2,}\.(.+){2,}/.test($(this).val()))) { // ERRORE : email NON corretta $(this).removeClass('is-valid').addClass('is-invalid'); $('#lbltxtEmail').html( fHTMLErrore( "The address is not correct." ) ); } else { $(this).removeClass('is-invalid').addClass('is-valid'); var data; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/2020/assets/ajax/checkContatto.php", data: "action=checkEmailCarrello&pstrEmail=" + $('#txtEmail').val(), success: function(data) { if ( $('#id_cliente').val() == '' ) { // Email corretta if ( data.email_exists == 1 ) { // AVVISO : email già in archivio $('#lbltxtEmail-login').removeClass('d-none').html( 'Hello ' + data.nome + ', your email is already registered on the site.
You can login if you want, or re-enter the data.' ); $('.row-scelta-registrazione, .row-scelta-registrazione-box').addClass('d-none'); $('#email_gia_registrata').val( 1 ); $(this).removeClass('is-valid').addClass('is-invalid'); } else { $('.row-scelta-registrazione, .row-scelta-registrazione-box').removeClass('d-none'); $('#email_gia_registrata').val( 0 ); } } } }); /* ajax */ } $('.loader-txtEmail').addClass('d-none'); }); $('input[name=scelta]').change(function() { if ( $(this).val() == 'registrazione' ) { $('.row-nessuna-registrazione-box').addClass('d-none'); $('.row-registrazione-box').removeClass('d-none'); $('#registra-newsletter').prop('checked', true); } else { $('.row-registrazione-box').addClass('d-none'); $('.row-nessuna-registrazione-box').removeClass('d-none'); //$('#registra-newsletter').prop('checked', false); //$('#txtPassword, #txtConfermaPassword').removeClass('is-invalid').addClass('is-valid'); $('#lbltxtPassword, #lbltxtConfermaPassword').html(''); } }); $('input[name=pagamento]').change(function() { $('#totale_ordine_loader').removeClass('d-none'); $('.pagamento_descrizione').addClass('d-none'); var pagid = $(this).val(); if ( $(this).prop('checked') ) { $( '.pagamento_descrizione_' + pagid ).removeClass('d-none'); } fAggiornaTotaleOrdine(); $('#totale_ordine_loader').addClass('d-none'); }); // nazione $('#cmbNazione').change(function() { if ( $(this).val() == 'IT' ) { $('#label_ricarica_postepay, #label_vaglia, #label_contrassegno').removeClass('d-none'); $('#col-nazione').addClass('col-lg-8'); $('#col-provincia').removeClass('d-none'); } else { $('#label_ricarica_postepay, #label_vaglia, #label_contrassegno').addClass('d-none'); if ( $("input[name=pagamento]:checked").val() == 'X_ID_RECORD_RICARICA_POSTEPAY' || $("input[name=pagamento]:checked").val() == 'vaglia' || $("input[name=pagamento]:checked").val() == 'contrassegno' ) { $('.pagamento_descrizione').addClass('d-none'); $('#pagamento_paypal').prop('checked', true); $( '#pagamento_span_paypal' ).addClass('active'); $( '.pagamento_descrizione_paypal' ).removeClass('d-none'); } $('#col-provincia').addClass('d-none'); $('#col-nazione').removeClass('col-lg-8'); } fAggiornaTotaleOrdine(); }); // provincia $('#cmbProvincia').change(function() { fAggiornaTotaleOrdine(); }); $('#verifica_codice_sconto').click(function() { $('#row-sconto-carrello').addClass('d-none'); $('#sconto_carrello_descrizione, #sconto_carrello_label').html( '' ); $('#sconto_carrello').val( 0 ); $('#codice_sconto_carrello').val( '' ); $('.fg-txtCodiceScontoInput').removeClass('has-error'); if ( $.trim( $('#txtCodiceScontoInput').val() ) == '' ) { $('#txtCodiceScontoInput').removeClass('is-valid').addClass('is-invalid').focus(); } else { $('.panel-hai-un-codice').addClass('d-none'); $('.panel-hai-un-codice-loader').removeClass('d-none'); var data; var blnVerifica = false; var strLabelTop = ""; var strLabel = ""; var strLabelType = ""; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/2020/assets/ajax/setCodiceSconto.php", data: "action=setCodiceSconto&id_cliente=" + $("#id_cliente").val() + "&codice_sconto=" + $('#txtCodiceScontoInput').val() + "&lang_current=" + $('#lang_current').val(), success: function(data) { $('.panel-hai-un-codice-loader').addClass('d-none'); if ( data.status == 'ok' ) { if ( data.verifica > 0 ) { blnVerifica = true; $('#sconto_carrello_descrizione').html( data.sconto_descrizione ); $('#sconto_carrello_label').html( data.sconto_valore_label ); $('#sconto_carrello').val( data.sconto_valore ); $('#codice_sconto_carrello').val( data.codice ); $('#row-sconto-carrello').removeClass('d-none'); $('#codice_success_label').html( data.sconto_success_label ); strLabelTop = "Ok"; strLabel = "The coupon has been entered correctly."; strLabelType = "success"; } else { strLabelTop = data.label_top; strLabel = data.label; strLabelType = data.label_type; } } else { swal("Ops...", "Unable to perform the operation.", "error"); } }, error: function(data) { swal("Ops...", "", "error"); } }); fAggiornaTotaleOrdine(); $('.panel-hai-un-codice-loader').addClass('d-none'); if ( blnVerifica ) $('.panel-hai-un-codice-success').removeClass('d-none'); else $('.panel-hai-un-codice').removeClass('d-none'); if ( strLabelTop != "" ) swal( strLabelTop, strLabel,strLabelType ); } }); $('#rimuovi_codice_sconto').click(function() { $('.panel-hai-un-codice-success').addClass('d-none'); $('.panel-hai-un-codice-loader').removeClass('d-none'); $('#row-sconto-carrello').addClass('d-none'); $('#sconto_carrello_descrizione, #sconto_carrello_label').html( '' ); $('#sconto_carrello').val( 0 ); $('#codice_sconto_carrello').val( '' ); $('#txtCodiceScontoInput').removeClass('is-valid').removeClass('is-invalid').val( '' ); fAggiornaTotaleOrdine(); $('.panel-hai-un-codice-loader').addClass('d-none'); $('.panel-hai-un-codice').removeClass('d-none'); swal( "Ok", "Lo sconto è stato rimosso.", "success" ); }); }); function fAggiornaTotaleOrdine() { $('#totale_ordine_loader').removeClass('d-none'); var data; var strID_Pagamento = $("input[name=pagamento]:checked").val(); var strNazione = $("#cmbNazione").val(); if ( strNazione == '' ) strNazione = 'IT'; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/2020/assets/ajax/setCarrello.php", data: "action=setTotaleCarrello" + "&id_cliente=" + $("#id_cliente").val() + "&provincia=" + $("#cmbProvincia").val() + "&nazione=" + strNazione + "&id_pagamento=" + strID_Pagamento + "&totale_peso=" + $("#totale_peso").val() + "&sconto=" + $("#sconto_carrello").val() + "&totale_carrello_prodotti=" + $("#totale_carrello_prodotti").val() + "&pstrLangCurrent=" + $("#lang_current").val(), success: function(data) { if ( data.status == 'ok' ) { $('#crl_spedizione_label').html( data.spedizione_label ); $('#crl_spedizione_costo_label').html( data.spedizione_costo ); $('#crl_contrassegno').html( data.contrassegno_costo ); $('#crl_paypal_commissioni').html( data.paypal_commissioni ); $('#crl_totale_label').html( data.totale_ordine ); $('#ordine_acquistabile').val( parseInt( data.ordine_acquistabile ) ); if ( parseInt( data.ordine_acquistabile ) > 0 ) { $('#completa-ordine').removeClass('d-none'); } else { $('#completa-ordine').addClass('d-none'); } if ( data.nazione == X_IT && ! parseInt( data.spedizione_gratis ) ) { $('#crl_spedizione_gratis').removeClass('d-none'); } else { $('#crl_spedizione_gratis').addClass('d-none'); } if ( data.nazione == X_IT && ! parseInt( data.contrassegno_gratis ) ) { $('#crl_contrassegno_gratis').removeClass('d-none'); } else { $('#crl_contrassegno_gratis').addClass('d-none'); } } else swal("Ops...", "Unable to perform the operation.", "error"); }, error: function(data) { swal("Ops...", "", "error"); } }); if ( strID_Pagamento == 'contrassegno' ) $('#row-contrassegno').removeClass('d-none'); else $('#row-contrassegno').addClass('d-none'); if ( strID_Pagamento == 'paypal' || strID_Pagamento == 'carta' || strID_Pagamento == 'postepay' ) $('#row-paypal-commissioni').removeClass('d-none'); else $('#row-paypal-commissioni').addClass('d-none'); $('#totale_ordine_loader').addClass('d-none'); } function fSaveData() { $('submit').focus(); $('#submitBut').addClass('d-none'); $('#submitLoad').removeClass('d-none'); var data; var strDestination = ''; var strID_Ordine = ''; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/2020/assets/ajax/sendOrder.php", data: $("#frmCompletaOrdine").serialize(), success: function(data) { $('#completaErrore').addClass('d-none'); if ( data.status == 'obbligatori' ) { $('#completaErrore').removeClass('d-none'); } else if ( data.status == 'non_acquistabile' ) { swal("Warning!", "Spiacente, non è possibile completare l'ordine.", "warning"); } else if ( data.status == 'ok' ) { strID_Ordine = data.id_ordine; strDestination = data.destination; } else swal("Ops...", "Unable to perform the operation.", "error"); }, error: function(data) { swal("Ops...", "", "error"); } }); if ( strID_Ordine != '' && strDestination != '' ) { location.href = strDestination; } else { $('#submitLoad').addClass('d-none'); $('#submitBut').removeClass('d-none'); } } // Controllo campi obbligatori function fCheckObbligatori() { var blnReturn = true; var strAlert = ""; $('submit').focus(); $('#submitBut').addClass('d-none'); $('#submitLoad').removeClass('d-none'); $('#panel-dati input, #panel-dati textarea, #panel-dati select').removeClass('is-invalid').removeClass('is-valid'); $(".lbl").html(""); var sceltaRegistrazione = $('#scelta_registrazione').prop('checked'); var strID_Contatto = ( $('#id_cliente').length ? $('#id_cliente').val() : '' ); // Controllo email if ( $("#txtEmail").val() != '' ) { $('#loader-txtEmail').removeClass('d-none'); $('#lbltxtEmail').html( '' ); if (!(/(.+)@(.+){2,}\.(.+){2,}/.test($('#txtEmail').val()))) { // ERRORE : email NON corretta blnReturn = false; $('#lbltxtEmail').html( fHTMLErrore( "The address is not correct." ) ); $('#txtEmail').removeClass('is-valid').addClass('is-invalid'); strAlert = "L'email non è corretta."; } $('#loader-txtEmail').addClass('d-none'); } $('.required').each(function() { if ( $.trim( $(this).val() ) == "" ) { blnReturn = false; //$( "#lbl" + $(this).attr("name") ).html( fHTMLErrore( "Required" ) ); $(this).removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) if ( $(this).attr("name") == "txtEmail" ) strAlert = "Enter your email address and data for shipment."; else strAlert = "LNG_FORM_INS_CAMPO: " + $( "#lbl" + $(this).attr("name") ).attr("title"); } else $( "#lbl" + $(this).attr("name") ).html(""); }); // Controllo indirizzzo if ( $('#cmbNazione').val() == 'IT' ) { if ( $.trim( $('#cmbProvincia').val() ) == '' ) { blnReturn = false; //$('#lblcmbProvincia').html( fHTMLErrore( "Required" ) ); $('#cmbProvincia').removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "LNG_FORM_INS_PROVINCIA"; } else $('#lblcmbProvincia').html(""); } if ( $('#scelta_registrazione').prop('checked') && ! parseInt( $('#email_gia_registrata').val() ) ) { // Controllo password if ( $.trim( $('#txtPassword').val() ) == '' ) { blnReturn = false; //$("#lbltxtPassword").html( fHTMLErrore( "Required" ) ); $("#txtPassword").removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "LNG_FORM_INS_PASSWORD"; } else $("#lbltxtPassword").html(""); if ( $.trim( $('#txtConfermaPassword').val() ) == '' ) { blnReturn = false; //$("#lbltxtConfermaPassword").html( fHTMLErrore( "Required" ) ); $("#txtConfermaPassword").removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "LNG_FORM_INS_PASSWORD_CONFERMA"; } else $("#lbltxtConfermaPassword").html(""); if ( $('#txtPassword').val() != '' || $('#txtConfermaPassword').val() != '' ) { if ( $('#txtPassword').val() != $('#txtConfermaPassword').val() ) { blnReturn = false; $('#lbltxtConfermaPassword').html( fHTMLErrore( "" ) ); $( "#txtConfermaPassword" ).removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "The password is not equal."; } else $('#lbltxtConfermaPassword').html(""); } // Controllo domanda if ( $('#cmbDomanda').val() == '' ) { blnReturn = false; //$("#lblcmbDomanda").html( fHTMLErrore( "Required" ) ); $("#cmbDomanda").removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "Domanda di sicurezza"; } else $("#lblcmbDomanda").html(""); // Controllo risposta if ( $.trim( $('#txtRisposta').val() ) == '' ) { blnReturn = false; //$("#lbltxtRisposta").html( fHTMLErrore( "Required" ) ); $("#txtRisposta").removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "Risposta di sicurezza"; } else $("#lbltxtRisposta").html(""); } // Controllo privacy if( ! $('#privacy').prop('checked') ) { blnReturn = false; $('#lblprivacy').html( fHTMLErrore( "Acceptance required." ) ); //$( ".fg-privacy" ).addClass( "has-error" ); if ( strAlert == "" ) strAlert = "LNG_FORM_ACCETTAZIONE2"; } else $('#lblprivacy').html(""); if ( $('#sono_azienda').prop('checked') ) { // Controllo RagioneSociale if ( $.trim( $('#txtRagioneSociale').val() ) == "" ) { blnReturn = false; //$( "#lbltxtRagioneSociale" ).html( fHTMLErrore( "Required" ) ); $('#txtRagioneSociale').removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "Enter your company name"; } else { $( "#lbltxtRagioneSociale" ).html(""); } // Controllo Partita IVA if ( $.trim( $('#txtPartitaIva').val() ) == "" ) { blnReturn = false; //$( "#lbltxtPartitaIva" ).html( fHTMLErrore( "Required" ) ); $('#txtPartitaIva').removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "Enter your VAT code"; } else { $( "#lbltxtPartitaIva" ).html(""); $('#lbltxtPartitaIva').html( '' ); var data; var intExists = 0; var blnSaved = false; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/2020/assets/ajax/checkContatto.php", data: "action=checkPartitaIva&pstrPartitaIva=" + $("#txtPartitaIva").val() + "&pstrID_Contatto=" +strID_Contatto, success: function(data) { intExists = data.partita_iva_exists; if ( intExists == 1 && ! $('#scelta_nessuna_registrazione').prop('checked') ) { // ERRORE : valore NON unico blnReturn = false; $('#lbltxtPartitaIva').html( fHTMLErrore( "The value already exist." ) ); $('#txtPartitaIva').removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "LNG_FORM_PIVAINARCHIVIO"; } else { // OK : valore unico $('#lbltxtPartitaIva').html(""); } if ( data.status == 'ok' ) blnSaved = true; else swal("Ops...", "LNG_AJAX_VERIFICA", "error"); }, error: function(data) { swal("Ops...", "Procedure uncompleted.", "error"); } }); } } $('#submitLoad').addClass('d-none'); $('#submitBut').removeClass('d-none'); if ( ! blnReturn ) { $('#completaErrore').removeClass('d-none'); if ( strAlert != "" ) swal("Warning!", strAlert, "error"); } else $('#completaErrore').addClass('d-none'); return blnReturn; } function fHTMLErrore( pstr ) { return '' + pstr + ''; } // Aggiorna quantita function fAggiornaQuantita( pstrKey, pintID_Riga ) { fLoading( 1 ); var pintQuantita = $('#quantita_'+pintID_Riga).val(); $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/2020/assets/ajax/setCarrello.php", data: "action=aggiornaQuantita&pstrKey=" + pstrKey + "&pintID_Riga=" + pintID_Riga + "&pintQuantita=" + pintQuantita, success: function(data) { if ( data.status == 'ok' ) { location.href = '/en/cart/' + ( data.max == 'exceed' ? '?max=exceed' : '' ); } else { fLoading( 0 ); swal("Ops...", "Unable to perform the operation.", "error"); } }, error: function(data) { fLoading( 0 ); swal("Ops...", "", "error"); } }); /* ajax */ } function fAggiornaQuantitaButton( pstrKey, pintID_Riga, pintQuantita ) { fLoading( 1 ); $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/2020/assets/ajax/setCarrello.php", data: "action=aggiornaQuantita&pstrKey=" + pstrKey + "&pintID_Riga=" + pintID_Riga + "&pintQuantita=" + pintQuantita, success: function(data) { if ( data.status == 'ok' ) { location.href = '/en/cart/' + ( data.max == 'exceed' ? '?max=exceed' : '' ); } else { fLoading( 0 ); swal("Ops...", "Unable to perform the operation.", "error"); } }, error: function(data) { fLoading( 0 ); swal("Ops...", "", "error"); } }); /* ajax */ } // Rimuovi prodotto function fDelProd( pstrKey, pintID_Riga ) { swal({ title: "Warning!", text: "Remove this product from the cart?", type: "warning", showCancelButton: true, cancelButtonText: "No, cancel", confirmButtonText: "Yes, delete!", closeOnConfirm: true }, function() { fLoading( 1 ); $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/2020/assets/ajax/setCarrello.php", data: "action=rimuoviProdotto&pstrKey=" + pstrKey + "&pintID_Riga=" + pintID_Riga, success: function(data) { if ( data.status == 'ok' ) { location.href = '/en/cart/'; } else swal("Ops...", "Unable to perform the operation.", "error"); }, error: function(data) { swal("Ops...", "", "error"); } }); /* ajax */ }); } // Svuota carrello function fSvuotaCarrello( pstrKey ) { swal({ title: "Warning!", text: "Remove all products from the cart?", type: "warning", showCancelButton: true, cancelButtonText: "No, cancel", confirmButtonText: "Yes, delete!", closeOnConfirm: true }, function() { fLoading( 1 ); $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/2020/assets/ajax/setCarrello.php", data: "action=svuotaCarrello&pstrKey=" + pstrKey, success: function(data) { if ( data.status == 'ok' ) { location.href = '/en/cart/'; } else swal("Ops...", "Unable to perform the operation.", "error"); }, error: function(data) { swal("Ops...", "", "error"); } }); /* ajax */ }); }