$( function() { $("#completa-ordine").click(function() { if ( parseInt( $('#ordine_acquistabile').val() ) > 0 ) { if ( fCheckObbligatori() ) fSaveData(); } else if ( $("#cmbNazione").val() == 'IT' && $.trim( $('#cmbProvincia').val() ) == '' ) swal( "Attenzione!", "scegli la provincia", "error" ); else swal( "Attenzione!", "L'ordine non è disponibile.", "error" ); }); $('#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( "LNG_FORM_OBBLIGATORIO2" ) ); } else if (!(/(.+)@(.+){2,}\.(.+){2,}/.test($(this).val()))) { // ERRORE : email NON corretta $(this).removeClass('is-valid').addClass('is-invalid'); $('#lbltxtEmail').html( fHTMLErrore( "L'email non è corretta." ) ); } else { $(this).removeClass('is-invalid').addClass('is-valid'); var data; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/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( 'Ciao ' + data.nome + ', la tua email è già iscritta al sito.
Puoi fare il login se vuoi, oppure inserisci nuovamente i dati.' ); $('.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'); }); // tipo_registrazione $('.tipo_registrazione').change(function() { if ( $('.tipo_registrazione:checked').val() == 'azienda' ) { // AZIENDA $('.fg-txtRagioneSociale, .fg-txtPartitaIva').removeClass('d-none'); $('.fg-txtCodiceFiscale').addClass('d-none'); } else { // PRIVATO $('.fg-txtRagioneSociale, .fg-txtPartitaIva').addClass('d-none'); $('.fg-txtCodiceFiscale').removeClass('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-indirizzo').addClass('col-lg-5'); $('#col-via, #col-civico, #col-provincia').removeClass('d-none'); } else { $('#label_ricarica_postepay, #label_vaglia, #label_contrassegno').addClass('d-none'); if ( $("input[name=pagamento]:checked").val() == '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-via, #col-civico, #col-provincia').addClass('d-none'); $('#col-indirizzo').removeClass('col-lg-5'); $('#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/default/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 = "Lo sconto è stato inserito correttamente."; strLabelType = "success"; } else { strLabelTop = data.label_top; strLabel = data.label; strLabelType = data.label_type; } } else { swal("Ops...", "Impossibile effettuare l'operazione.", "error"); } }, error: function(data) { swal("Ops...", "Procedura non completata.", "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/default/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...", "Impossibile effettuare l'operazione.", "error"); }, error: function(data) { swal("Ops...", "Procedura non completata.", "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/default/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("Attenzione!", "Spiacente, non è possibile completare l'ordine.", "warning"); } else if ( data.status == 'ok' ) { strID_Ordine = data.id_ordine; strDestination = data.destination; } else swal("Ops...", "Impossibile effettuare l'operazione.", "error"); }, error: function(data) { swal("Ops...", "Procedura non completata.", "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( "L'email non è corretta." ) ); $('#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( "LNG_FORM_OBBLIGATORIO2" ) ); $(this).removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) if ( $(this).attr("name") == "txtEmail" ) strAlert = "Inserisci la tua email e i dati per la spedizione."; else strAlert = "Inserisci il 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( "LNG_FORM_OBBLIGATORIO2" ) ); $('#cmbProvincia').removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "Inserisci la provincia"; } else $('#lblcmbProvincia').html(""); if ( $.trim( $('#txtCivico').val() ) == '' ) { blnReturn = false; //$('#lbltxtCivico').html( fHTMLErrore( "LNG_FORM_OBBLIGATORIO2" ) ); $('#txtCivico').removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "N. civico"; } else $('#lbltxtCivico').html(""); } if ( $('#scelta_registrazione').prop('checked') && ! parseInt( $('#email_gia_registrata').val() ) ) { // Controllo password if ( $.trim( $('#txtPassword').val() ) == '' ) { blnReturn = false; //$("#lbltxtPassword").html( fHTMLErrore( "LNG_FORM_OBBLIGATORIO2" ) ); $("#txtPassword").removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "Inserisci la password"; } else $("#lbltxtPassword").html(""); if ( $.trim( $('#txtConfermaPassword').val() ) == '' ) { blnReturn = false; //$("#lbltxtConfermaPassword").html( fHTMLErrore( "LNG_FORM_OBBLIGATORIO2" ) ); $("#txtConfermaPassword").removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "Inserisci la conferma password"; } 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 = "La password non è uguale."; } else $('#lbltxtConfermaPassword').html(""); } // Controllo domanda if ( $('#cmbDomanda').val() == '' ) { blnReturn = false; //$("#lblcmbDomanda").html( fHTMLErrore( "LNG_FORM_OBBLIGATORIO2" ) ); $("#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( "LNG_FORM_OBBLIGATORIO2" ) ); $("#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( "Accettazione obbligatoria." ) ); //$( ".fg-privacy" ).addClass( "has-error" ); if ( strAlert == "" ) strAlert = "L'accettazione delle norme sulla privacy è obbligatoria"; } else $('#lblprivacy').html(""); // Controllo RagioneSociale if ( $('.tipo_registrazione:checked').val() != 'privato' ) { if ( $.trim( $('#txtRagioneSociale').val() ) == "" ) { blnReturn = false; //$( "#lbltxtRagioneSociale" ).html( fHTMLErrore( "LNG_FORM_OBBLIGATORIO2" ) ); $('#txtRagioneSociale').removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "Inserisci la ragione sociale"; } else { $( "#lbltxtRagioneSociale" ).html(""); } } var blnEstero = ( $('#cmbNazione').val() != 'IT' ? true : false ); // Controllo Codice fiscale if ( ! blnEstero && $('.tipo_registrazione:checked').val() == 'privato' ) { if ( $.trim( $('#txtCodiceFiscale').val() ) == "" ) { blnReturn = false; //$( "#lbltxtCodiceFiscale" ).html( fHTMLErrore( "LNG_FORM_OBBLIGATORIO2" ) ); $('#txtCodiceFiscale').removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "Inserisci il codice fiscale"; } else { $( "#lbltxtCodiceFiscale" ).html(""); $('#lbltxtCodiceFiscale').html( '' ); var data; var intExists = 0; var blnSaved = false; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/checkContatto.php", data: "action=checkCodiceFiscale&pstrCodiceFiscale=" + $("#txtCodiceFiscale").val() + "&pstrID_Contatto=" +strID_Contatto, success: function(data) { intExists = data.codice_fiscale_exists; if ( intExists == 1 && ! $('#scelta_nessuna_registrazione').prop('checked') ) { // ERRORE : valore NON unico blnReturn = false; $('#lbltxtCodiceFiscale').html( fHTMLErrore( "Il valore è già in archivio." ) ); $('#txtCodiceFiscale').removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "Il codice fiscale è già in archivio"; } else { // OK : valore unico $('#lbltxtCodiceFiscale').html(""); } if ( data.status == 'ok' ) blnSaved = true; else swal("Ops...", "LNG_AJAX_VERIFICA", "error"); }, error: function(data) { swal("Ops...", "Procedura non completata.", "error"); } }); } } // Controllo Partita IVA if ( $('.tipo_registrazione:checked').val() != 'privato' ) { if ( $.trim( $('#txtPartitaIva').val() ) == "" ) { blnReturn = false; //$( "#lbltxtPartitaIva" ).html( fHTMLErrore( "LNG_FORM_OBBLIGATORIO2" ) ); $('#txtPartitaIva').removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "Inserisci la partita IVA"; } else { $( "#lbltxtPartitaIva" ).html(""); $('#lbltxtPartitaIva').html( '' ); var data; var intExists = 0; var blnSaved = false; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/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( "Il valore è già in archivio." ) ); $('#txtPartitaIva').removeClass('is-valid').addClass('is-invalid'); if ( strAlert == "" ) strAlert = "La partita IVA è già in archivio"; } else { // OK : valore unico $('#lbltxtPartitaIva').html(""); } if ( data.status == 'ok' ) blnSaved = true; else swal("Ops...", "LNG_AJAX_VERIFICA", "error"); }, error: function(data) { swal("Ops...", "Procedura non completata.", "error"); } }); } } $('#submitLoad').addClass('d-none'); $('#submitBut').removeClass('d-none'); if ( ! blnReturn ) { $('#completaErrore').removeClass('d-none'); if ( strAlert != "" ) swal("Attenzione!", 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/default/assets/ajax/setCarrello.php", data: "action=aggiornaQuantita&pstrKey=" + pstrKey + "&pintID_Riga=" + pintID_Riga + "&pintQuantita=" + pintQuantita, success: function(data) { if ( data.status == 'ok' ) { location.href = '/carrello/' + ( data.max == 'exceed' ? '?max=exceed' : '' ); } else { fLoading( 0 ); swal("Ops...", "Impossibile effettuare l'operazione.", "error"); } }, error: function(data) { fLoading( 0 ); swal("Ops...", "Procedura non completata.", "error"); } }); /* ajax */ } function fAggiornaQuantitaButton( pstrKey, pintID_Riga, pintQuantita ) { fLoading( 1 ); $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/setCarrello.php", data: "action=aggiornaQuantita&pstrKey=" + pstrKey + "&pintID_Riga=" + pintID_Riga + "&pintQuantita=" + pintQuantita, success: function(data) { if ( data.status == 'ok' ) { location.href = '/carrello/' + ( data.max == 'exceed' ? '?max=exceed' : '' ); } else { fLoading( 0 ); swal("Ops...", "Impossibile effettuare l'operazione.", "error"); } }, error: function(data) { fLoading( 0 ); swal("Ops...", "Procedura non completata.", "error"); } }); /* ajax */ } // Rimuovi prodotto function fDelProd( pstrKey, pintID_Riga ) { swal({ title: "Attenzione!", text: "Vuoi cancellare questo prodotto dal carrello?", type: "warning", showCancelButton: true, cancelButtonText: "No, annulla", confirmButtonText: "Si, cancella!", closeOnConfirm: true }, function() { fLoading( 1 ); $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/setCarrello.php", data: "action=rimuoviProdotto&pstrKey=" + pstrKey + "&pintID_Riga=" + pintID_Riga, success: function(data) { if ( data.status == 'ok' ) { location.href = '/carrello/'; } else swal("Ops...", "Impossibile effettuare l'operazione.", "error"); }, error: function(data) { swal("Ops...", "Procedura non completata.", "error"); } }); /* ajax */ }); } // Svuota carrello function fSvuotaCarrello( pstrKey ) { swal({ title: "Attenzione!", text: "Vuoi cancellare tutti i prodotti dal carrello?", type: "warning", showCancelButton: true, cancelButtonText: "No, annulla", confirmButtonText: "Si, cancella!", closeOnConfirm: true }, function() { fLoading( 1 ); $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/setCarrello.php", data: "action=svuotaCarrello&pstrKey=" + pstrKey, success: function(data) { if ( data.status == 'ok' ) { location.href = '/carrello/'; } else swal("Ops...", "Impossibile effettuare l'operazione.", "error"); }, error: function(data) { swal("Ops...", "Procedura non completata.", "error"); } }); /* ajax */ }); }