1var checkoutcustomer = {}; 2 3// Urls 4var ajaxCustomer = helper.getBaseUrl() + '/ajax/checkout/cliente.php'; 5var ajaxLogin = helper.getBaseUrl() + '/ajax/cliente/login.php'; 6 7// Static Variables 8var emailValidating = ".validating-email"; 9var emailPasswordValidating = ".validating-email-password"; 10var passwordEmailValidating = ".validating-password-email"; 11var accessValidating = ".validating-access"; 12var personalSelector = ".personal"; 13var personalValidating = ".personal .validating-content"; 14var personalValidated = ".personal .validated-content"; 15checkoutcustomer.emailInput = ".validating-email input[name='email']"; 16checkoutcustomer.emailPasswordInput = ".validating-email-password input[name='email']"; 17checkoutcustomer.passwordEmailInput = ".validating-password-email input[name='password']"; 18var infoSelector = ".waiting-info"; 19var customerLoadedData = null; 20var enableEdit = false; 21var showGuestModal = false; 22var missingDocument = false; 23var showLockMessage = false; 24var loginType = null; 25checkoutcustomer.blockChangeCnpj = false; 26 27// Modal Selectors 28var errorLabelSelector = '[data-error-container]'; 29var errorLabelContainerSelector = '.warning-container'; 30var securityErrorLabelSelector = '[data-security-error]'; 31var securityErrorLabelContainerSelector = '.security-warning-container'; 32var okLabelSelector = '.label.ok'; 33checkoutcustomer.loginTypeSelector = '[data-login-type]'; 34 35checkoutcustomer.loginTypes = {guestCheckout: 1, passwordLogin: 2}; 36 37checkoutcustomer.initialize = function() { 38 var selectoremail = ".validating-email button"; 39 var selectorpassword = ".validating-email-password button"; 40 41 var event = "click"; 42 43 selector = checkoutcustomer.loginTypeSelector; 44 loginType = $(selector).val(); 45 46 if (loginType == checkoutcustomer.loginTypes.guestCheckout) { 47 $(document).on(event, selectoremail, function(e) { 48 checkoutSetup.loadLoginData(); 49 50 if ($("#useinvisiblerecaptcha").val() != 'true') { 51 checkoutcustomer.checkEmail(); 52 } else { 53 checkout.sendInvisibleRecaptchaValidation('checkoutcustomer.validateRecaptcha'); 54 } 55 }); 56 } else { 57 $(document).on(event, selectorpassword, function(e) { 58 e.preventDefault(); 59 60 checkoutSetup.loadLoginData(); 61 62 if ($("#useinvisiblerecaptcha").val() != 'true') { 63 checkoutcustomer.checkEmailAndPassword(); 64 } else { 65 checkout.sendInvisibleRecaptchaValidation('checkoutcustomer.validateRecaptcha'); 66 } 67 }); 68 } 69} 70 71// Verifica se o cliente existe de acordo com o email 72checkoutcustomer.checkEmail = function() { 73 var email = $(checkoutcustomer.emailInput).val(); 74 75 var data = { 76 act: "verificaremail", 77 email: email 78 }; 79 80 loading.show(personalSelector); 81 82 checkoutSetup.ajaxCheckoutCache(ajax.POST, ajaxCustomer, data, 'checkoutcustomer.handleCustomer'); 83} 84 85// Verifica se o cliente existe de acordo com o email e senha 86checkoutcustomer.checkEmailAndPassword = function() { 87 var email = $(checkoutcustomer.emailPasswordInput).val(); 88 var password = $(checkoutcustomer.passwordEmailInput).val(); 89 90 checkoutcustomer.handleCustomerLoginPassword(email,password); 91} 92 93checkoutcustomer.validateRecaptcha = function(response) { 94 if (!response.data || !response.data.data) { 95 $("#email-error").text("Desculpe, não foi possÃvel finalizar sua requisição, tente novamente mais tarde."); 96 return; 97 } 98 99 checkoutcustomer.verifyLoginType(); 100} 101 102checkoutcustomer.verifyLoginType = function() { 103 selector = checkoutcustomer.loginTypeSelector; 104 loginType = $(selector).val(); 105 106 if (loginType == checkoutcustomer.loginTypes.passwordLogin) { 107 return checkoutcustomer.checkEmailAndPassword(); 108 } 109 return checkoutcustomer.checkEmail(); 110} 111 112// Verifica travas de pedido pendente 113checkoutcustomer.checkPendingOrderLock = function() { 114 var customerEmail = $(checkoutcustomer.emailInput).length ? $(checkoutcustomer.emailInput).val() : null; 115 var data = { 116 act: "verificartravapedidoaberto", 117 email: customerEmail 118 }; 119 120 loading.show(personalSelector); 121 122 checkoutSetup.ajaxCheckoutCache(ajax.POST, ajaxCustomer, data, 'checkoutcustomer.handleLocks'); 123} 124 125checkoutcustomer.handleLocks = function(response) { 126 loading.hide(); 127 128 checkoutcustomer.hidePendingOrderMessage(); 129 130 if (response.data.data == 1 || response.data.data == null) { 131 return; 132 } 133 134 if (response.data.data == 2) { 135 checkoutcustomer.showPendingOrderMessage(); 136 } else if (response.data.data == 3) { 137 checkoutcustomer.showPendingOrderMessage('Não é possÃvel prosseguir com pedidos pendentes.'); 138 checkoutcustomer.lockOrderCompletion('Prosseguimento bloqueado'); 139 } 140} 141 142checkoutcustomer.showPendingOrderMessage = function(message = null) { 143 var alertSelector = '[data-pending-order-alert]'; 144 var textSelector = '[data-pending-order-alert-text]'; 145 146 if (!$(alertSelector).length) { 147 return; 148 } 149 150 if (!message) { 151 message = "Você possui pedidos pendentes."; 152 } 153 154 if ($(textSelector).length) { 155 $(textSelector).html(message); 156 } 157 158 $(alertSelector).show(); 159} 160 161checkoutcustomer.hidePendingOrderMessage = function() { 162 var alertSelector = '[data-pending-order-alert]'; 163 164 if (!$(alertSelector).length) { 165 return; 166 } 167 168 $(alertSelector).hide(); 169} 170 171checkoutcustomer.lockOrderCompletion = function(lockMessage) { 172 var lockInputSelector = '[data-order-lock]'; 173 174 if (!$(lockInputSelector).length) { 175 return; 176 } 177 178 if (lockMessage) { 179 $(infoSelector).html(lockMessage); 180 } 181 182 $(lockInputSelector).val("true"); 183} 184 185checkoutcustomer.unlockOrderCompletion = function() { 186 var lockInputSelector = '[data-order-lock]'; 187 188 if (!$(lockInputSelector).length) { 189 return; 190 } 191 192 $(infoSelector).html("Aguardando preenchimento de dados") 193 $(lockInputSelector).val("false"); 194} 195
196checkoutcustomer.isOrderCompletionLocked = function() { 197 var lockInputSelector = '[data-order-lock]'; 198 199 if (!$(lockInputSelector).length) { 200 return false; 201 } 202 203 return $(lockInputSelector).val() == 'true'; 204} 205 206// Logica de tratamento de clientes novos e existentes 207// Se o cliente existir faz o guest login, se não habilita o form de cadastro 208checkoutcustomer.handleCustomer = function(checkEmail) { 209 loading.hide(); 210 211 checkoutcustomer.handleCustomerLoginGuest(checkEmail); 212} 213 214checkoutcustomer.handleCustomerLoginPassword = function(email, password) { 215 var dataRequestCustomer = { 216 act:"logarComEmaileSenha", 217 email: email, 218 senha: password 219 }; 220 221 loading.show(personalSelector); 222 223 checkoutSetup.ajaxCheckoutCache(ajax.POST, ajaxLogin, dataRequestCustomer, 'checkoutcustomer.handleLoginGuestOrPassword'); 224} 225 226checkoutcustomer.handleCustomerLoginGuest = function(checkEmail) { 227 var emailButtonContainer = ".validating-email button"; 228 229 if (checkEmail.message) { 230 var formControls = $('.form-control'); 231 formControls.removeClass('valid').addClass('error'); 232 233 var error = "<span class='error-field-list'>" + checkEmail.message + "</span>"; 234 ajaxutils.showAlertModal("", "Ops! Algo deu errado <br>" + error, "Não conseguimos realizar seu cadastro :("); 235 236 return; 237 } 238 239 if (checkEmail.data.data == true) { 240 var email = $(checkoutcustomer.emailInput).val(); 241 242 var dataRequestCustomer = { 243 act: "loginguest", 244 email: email 245 }; 246 247 loading.show(personalSelector); 248 249 checkoutSetup.ajaxCheckoutCache(ajax.POST, ajaxLogin, dataRequestCustomer, 'checkoutcustomer.handleLoginGuestOrPassword'); 250 } else { 251 $(checkoutcustomer.emailInput).prop("disabled",true); 252 $(personalValidating).removeClass("d-none"); 253 $(emailButtonContainer).addClass("d-none"); 254 checkoutcustomer.fillCustomerData(); 255 layout.companyIeExempt(); 256 257 checkoutcustomer.leadTracker(); 258 } 259} 260 261checkoutcustomer.changeEmailEvent = function() { 262 var selectorSubmit = ".change-email"; 263 var emailButtonContainer = ".validating-email button"; 264 var event = "click"; 265 266 $(document).on(event, selectorSubmit, function(e) { 267 $(checkoutcustomer.emailInput).prop("disabled",false); 268 $(personalValidating).addClass("d-none"); 269 $(emailButtonContainer).removeClass("d-none"); 270 checkoutcustomer.showAccessValidating(); 271 customerLoadedData = null; 272 if (enableEdit) { 273 checkoutcustomer.logout(); 274 } 275 }); 276 277} 278 279// Verifica o login guest ou login password, se não houver erro carrega os dados do cliente 280checkoutcustomer.handleLoginGuestOrPassword = function(loginData) { 281 loading.hide(); 282 if (loginData.error == true) { 283 errorMessages = loginData.message; 284 285 if (errorMessages.securityLoginMessage) { 286 ajaxutils.showAlertModal("", errorMessages.securityLoginMessage, "Ops! Algo deu errado"); 287 } else if (errorMessages.failedLoginMessage) { 288 ajaxutils.showAlertModal("", errorMessages.failedLoginMessage ,"Tivemos problemas com seu login"); 289 } else if (errorMessages) { 290 ajaxutils.showAlertModal("", errorMessages ,"Tivemos problemas com seu login"); 291 } else { 292 ajaxutils.showAlertModal("", "Tivemos problemas com seu login", "Ops! Algo deu errado"); 293 } 294 295 return; 296 } 297 298 if (loginData.data.data == true) { 299 showGuestModal = true; 300 checkoutcustomer.getCustomerData(); 301 302 selector = checkoutcustomer.loginTypeSelector; 303 loginType = $(selector).val(); 304 305 if (loginType == checkoutcustomer.loginTypes.passwordLogin) { 306 checkout.loginEvent('password'); 307 } else { 308 checkout.loginEvent('guest'); 309 } 310 311 $(document).on('checkout.customer.data.loaded', function(e, customer) { 312 if (customer.temClassificacao) { 313 location.reload(); 314 } else { 315 cart.removeItems(); 316 cart.listItems(); 317 } 318 }); 319 return; 320 } 321} 322 323checkoutcustomer.verifyShowGuestModal = function(customer) { 324 if (showGuestModal != true) { 325 return; 326 } 327 328 var _header = '<i class="fa fa-check-square-o highlight" aria-hidden="true"></i>Olá <span class="text-capitalize">' + customer + '</span>!'; 329 var _title = 'Identificamos que você já possui cadastro em nossa loja.'; 330 var _text = '<p>Para facilitar sua compra preenchemos os dados, mas por segurança eles não sã
330o exibidos. Caso deseje alterá-los, basta completar o login.</p>'; 331 332 ajaxutils.showAlertModal(_title, _text, _header, false, true); 333} 334 335// Carrega os dados do cliente 336checkoutcustomer.getCustomerData = function() { 337 checkoutcustomer.checkPendingOrderLock(); 338 339 var dataRequestCustomer = { 340 act: "dadoscliente" 341 }; 342 343 loading.show(personalSelector); 344 345 checkoutSetup.ajaxCheckoutCache(ajax.POST, ajaxLogin, dataRequestCustomer, 'checkoutcustomer.loadCustumerData'); 346} 347 348checkoutcustomer.getCustomerForTemplate = function(data) { 349 var customerInst = { 350 register: false, 351 customer: { 352 id: data.id || '', 353 displayName: checkoutcustomer.defineCustomerName(data)|| '', 354 email: data.email || '', 355 companyName: data.razao || '', 356 companyDisplayName: data.fantasia || '', 357 cnpj: data.cnpj || '', 358 foreignDocument: data.documentoEstrangeiro || '', 359 ie: data.ie || '', 360 exempt: data.isento ? 'checked' : '', 361 im: data.im || '', 362 name: data.nome || '', 363 lastname: data.sobrenome || '', 364 cpf: data.cpf || '', 365 rg: data.rg || '', 366 gender: data.sexo || '', 367 phone: data.telefone, 368 mobile: data.celular || '', 369 birthDate: data.dataNasc || '', 370 registerDate: data.dataCadastro || '', 371 register: false, 372 hasClassification: data.temClassificacao, 373 rememberedCard: data.rememberedCard || '', 374 hasCredit: data.temCredito, 375 credit: data.credito 376 } 377 }; 378 return customerInst; 379} 380 381checkoutcustomer.getCustomerStructureForTemplate = function() { 382 var customerInst = { 383 register: true, 384 customer: { 385 id: '', 386 displayName: '', 387 email: $(checkoutcustomer.emailPasswordInput).val() || $(checkoutcustomer.emailInput).val() || null, 388 companyName: '', 389 companyDisplayName: '', 390 cnpj: '', 391 foreignDocument: '', 392 ie: '', 393 exempt: '', 394 im: '', 395 name: '', 396 lastname: '', 397 cpf: '', 398 rg: '', 399 gender: '', 400 phone: '', 401 mobile: '', 402 birthDate: '', 403 registerDate: '', 404 newsletter: 'checked', 405 } 406 }; 407 return customerInst; 408} 409 410// Exibe os dados do cliente 411checkoutcustomer.loadCustumerData = function(customerData) { 412 var emailContainer = ".customer-email"; 413 var nameContainer = ".customer-name"; 414 415 loading.hide(); 416 if (customerData.error == true) { 417 ajaxutils.showAlertModal("", "Não foi possível carregar os dados de seu cadastro", "Ops! Algo deu errado"); 418 return; 419 } 420 421 var customer = customerData.data.data; 422 423 checkoutcustomer.showPersonalValidated(); 424 checkoutcustomer.hidePersonalValidating(); 425 checkoutcustomer.hideEmailValidating(); 426 checkoutcustomer.hideAccessValidating(); 427 428 var tplData = checkoutcustomer.getCustomerForTemplate(customer); 429 var tpl = template.getTemplate('cliente/checkoutclienteresumo', tplData); 430 $(".customer-summary-content").html(tpl); 431 432 customerLoadedData = tplData; 433 $("input[name=enderecoEmail]").val(customer.email); 434 435 if(!checkoutcustomer.checkCustomerData(customer)) { 436 return; 437 } 438 439 $(document).trigger('checkout.customer.data.loaded', [customer]); 440 checkoutcustomer.blockChangeCnpj = customer.travaCnpj; 441 442 //Apos o login permite a edição de dados cadastrais e logout 443 checkoutcustomer.initializeCustomerEdit(); 444 checkoutcustomer.logout(); 445 446 if (checkoutcustomer.isOrderCompletionLocked()) { 447 return; 448 } 449 450 checkoutPayment.selectDefaultPayment(); 451 checkoutcustomer.verifyShowGuestModal(checkoutcustomer.defineCustomerName(customer)); 452 453 if (checkoutcustomer.blockChangeCnpj) { 454 $(".edit-button").addClass('d-none'); 455 $(".edit-button").removeClass('d-block'); 456 } 457 458 address.initialize(); 459} 460 461checkoutcustomer.checkCustomerData = function(customer) { 462 missingDocument = false; 463 464 let missingCorporatePersonData = checkoutcustomer.missingCorporatePersonData(customer); 465 let missingIndividualPersonData = checkoutcustomer.missingIndividualPersonData(customer); 466 let missingForeignPersonData = checkoutcustomer.missingForeignPersonData(customer); 467 468 let missingInformation = missingCorporatePersonData && missingForeignPersonData && missingIndividualPersonData; 469 470 if (helper.isEmpty(customer.telefone) || missingInformation) { 471 missingDocument = true; 472 var callback = 'checkoutcustomer.enableEditByLoginType'; 473 checkoutcustomer.verifyCustomerGuest(callback); 474 return false;
475 } 476 477 return true; 478} 479 480checkoutcustomer.missingForeignPersonData = function(customer) { 481 if (helper.isEmpty(customer.nome) || helper.isEmpty(customer.sobrenome) || helper.isEmpty(customer.documentoEstrangeiro)) { 482 return true; 483 } 484 485 return false; 486} 487 488checkoutcustomer.missingCorporatePersonData = function (customer) { 489 if (helper.isEmpty(customer.cnpj) || helper.isEmpty(customer.razao) || (!customer.isento && helper.isEmpty(customer.ie))) { 490 return true; 491 } 492 493 return false; 494} 495 496checkoutcustomer.missingIndividualPersonData = function(customer) { 497 if (helper.isEmpty(customer.cpf) || helper.isEmpty(customer.nome) || helper.isEmpty(customer.sobrenome)) { 498 return true; 499 } 500 501 return false; 502} 503 504// Cria o objeto de cliente com base no customer-form 505checkoutcustomer.createCustomerObject = function() { 506 let personTab = "#fisica-tab"; 507 let companyTab = "#juridica-tab"; 508 let customer = new Object(); 509 510 let personName = null; 511 let personLastname = null; 512 let personCpf = null; 513 let companyName = null; 514 let companyCnpj = null; 515 let companyIe = null; 516 let companyIeExempt = null; 517 let phone = null; 518 let foreignPersonName = null; 519 let foreignPersonLastName = null; 520 let foreignPersonDocument = null; 521 let foreignPersonDocumentCountry = null; 522 let foreignPersonPhone = null; 523 524 let email = $(checkoutcustomer.emailInput).val(); 525 let newsletter = $(".customer-form input[name='newsletter']").is(':checked'); 526 let subscribeWhatsApp = $(".customer-form input[name='subscribeWhatsApp']").is(':checked'); 527 528 if ($(personTab).hasClass('active')) { 529 personName = $(".customer-form input[name='personName']").val(); 530 personLastname = $(".customer-form input[name='personLastname']").val(); 531 personCpf = $(".customer-form input[name='personCpf']").val(); 532 phone = $(".customer-form input[name='personPhone']").val(); 533 } else if ($(companyTab).hasClass('active')) { 534 companyName = $(".customer-form input[name='companyName']").val(); 535 companyCnpj = $(".customer-form input[name='companyCnpj']").val(); 536 companyIe = $(".customer-form input[name='companyIe']").val(); 537 companyIeExempt = $(".customer-form input[name='companyIeExempt']").is(':checked') ? '1' : '0'; 538 phone = $(".customer-form input[name='companyPhone']").val(); 539 } else { 540 foreignPersonName = $(".customer-form input[name='foreignPersonName']").val(); 541 foreignPersonLastName = $(".customer-form input[name='foreignPersonLastname']").val(); 542 foreignPersonDocument = $(".customer-form input[name='foreignPersonDoc']").val(); 543 foreignPersonDocumentCountry = $(".customer-form select[name='pais']").val(); 544 foreignPersonPhone = $(".customer-form input[name='foreignPersonPhone']").val(); 545 } 546 547 let customFields = []; 548 $('input[name^="custom"]').each(function(){ 549 customFields.push({index: $(this).attr('indice'), value: $(this).val()}); 550 }); 551 552 customer.customFields = customFields; 553 554 customer.email = email; 555 customer.personName = personName; 556 customer.personLastname = personLastname; 557 customer.personCpf = personCpf; 558 customer.companyName = companyName; 559 customer.companyCnpj = companyCnpj; 560 customer.companyIe = companyIe; 561 customer.companyIeExempt = companyIeExempt; 562 customer.phone = phone; 563 customer.newsletter = newsletter; 564 customer.subscribeWhatsApp = subscribeWhatsApp; 565 customer.foreignPersonName = foreignPersonName; 566 customer.foreignPersonLastName = foreignPersonLastName; 567 customer.foreignPersonDocument = foreignPersonDocument; 568 customer.foreignPersonDocumentCountry = foreignPersonDocumentCountry; 569 customer.foreignPersonPhone = foreignPersonPhone; 570 customer.fantasyName = $(".customer-form input[name='fantasyName']").val(); 571 customer.municipalityInscription = $(".customer-form input[name='municipalityInscription']").val(); 572 customer.rg = $(".customer-form input[name='rg']").val(); 573 customer.birthDate = $(".customer-form input[name='birthDate']").val(); 574 customer.gender = $(".customer-form select[name='gender']").val() 575 customer.cellPhone = $(".customer-form input[name='cellPhone']").val(); 576 customer.origin = $(".customer-form select[name='origin']").val(); 577 customer.purchaseType = $(".customer-form input[name='purchaseType']").val(); 578 579 return customer; 580} 581 582// Cadastra o cliente 583checkoutcustomer.registerCustomer = function() { 584 var selectorSubmit = "#register-customer"; 585 var event = "click"; 586 587 $(document).on(event, selectorSubmit, function(e) { 588 if (!checkoutcustomer.areTermsOfUseAgreed()) { 589 e.preventDefault();
590 ajaxutils.showAlertModal('', "à necessário aceitar os termos de uso para efetuar o cadastro", "Informação"); 591 return; 592 } 593 594 var validCustomer = validator.isCustomerValid(); 595 if (validCustomer == false) { 596 ajaxutils.showAlertModal("", "Precisamos de algumas informações para realizar o seu cadastro : <br>" + validator.customerErrorMsg, "Não conseguimos realizar seu cadastro :("); 597 return; 598 } 599 var customer = checkoutcustomer.createCustomerObject(); 600 601 var phone = customer.phone ? customer.phone : customer.foreignPersonPhone; 602 var celphone = phone.replace(/\D/g, '').length == 11 ? phone : ''; 603 604 var data = { 605 act: "cadastrar", 606 login: true, 607 email: customer.email, 608 origem: customer.origin, 609 razao: customer.companyName, 610 cnpj: customer.companyCnpj, 611 ie: customer.companyIe, 612 isento: customer.companyIeExempt, 613 nome: customer.personName ? customer.personName : customer.foreignPersonName, 614 sobrenome: customer.personLastname ? customer.personLastname : customer.foreignPersonLastName, 615 cpf: customer.personCpf, 616 telefone: phone, 617 celular: celphone, 618 receberNews: customer.newsletter, 619 receberWhatsApp: customer.subscribeWhatsApp, 620 documentoEstrangeiro: customer.foreignPersonDocument, 621 documentoEstrangeiroPais: customer.foreignPersonDocumentCountry, 622 fantasia: customer.fantasyName, 623 im: customer.municipalityInscription, 624 rg: customer.rg, 625 dataNasc: customer.birthDate, 626 sexo: customer.gender, 627 celular: customer.cellPhone, 628 origem: customer.origin, 629 tipoCompra: customer.purchaseType, 630 custom: customer.customFields 631 }; 632 633 loading.show(personalSelector); 634 checkoutSetup.registerCustomer(data, 'checkoutcustomer.handleCustomerRegister'); 635 }); 636} 637 638// Verifica se não houve erros no cadastro, caso positivo carrega os dados do cliente 639checkoutcustomer.handleCustomerRegister = function(customer) { 640 loading.hide(); 641 if (('error' in customer && customer.error) || ('data' in customer.data && customer.data.data == false)) { 642 if (customer.message) { 643 ajaxutils.showAlertModal("", "Não conseguimos realizar seu cadastro :( <br>" + customer.message, "Ops! Algo deu errado" ); 644 return; 645 } 646 647 ajaxutils.showAlertModal("", "Não conseguimos realizar seu cadastro :(", "Ops! Algo deu errado"); 648 return; 649 } 650 651 $(document).trigger('checkout.customer.registered'); 652 checkout.loginEvent('cadastro'); 653 checkoutcustomer.registerTracker(); 654 checkoutcustomer.getCustomerData(); 655} 656 657// Logout 658checkoutcustomer.logout = function() { 659 var selector = ".logout-button"; 660 var event = "click"; 661 662 $(document).on(event, selector, function(e) { 663 var data = { 664 act: "logout" 665 }; 666 loading.show(); 667 ajax.enqueue(ajax.POST, ajaxLogin, data, 'checkoutcustomer.handleLogout'); 668 }); 669} 670 671// Verifica o logout, caso não haja erros recarrega a pagina 672checkoutcustomer.handleLogout = function(logout) { 673 loading.hide(); 674 if (logout.data.data == true) { 675 checkout.loginEvent('logout'); 676 677 location.reload(); 678 } 679} 680 681// Cria o evento do botão de editar cliente 682checkoutcustomer.initializeCustomerEdit = function() { 683 var selector = ".edit-button"; 684 var event = "click"; 685 686 if (checkoutcustomer.blockChangeCnpj) { 687 return; 688 } 689 690 $(document).on(event, selector, function(e) { 691 var callback = 'checkoutcustomer.enableEditByLoginType'; 692 checkoutcustomer.verifyCustomerGuest(callback); 693 }); 694} 695 696checkoutcustomer.verifyCustomerGuest = function(callback) { 697 callback = callback ||'checkoutcustomer.enableEditByLoginType'; 698 var data = { 699 act: "verificarlogadoguest" 700 }; 701 702 loading.show(personalSelector); 703 /** 704 * Always remember to use 'loading.hide()' on the callback function 705 */ 706 checkoutSetup.ajaxCheckoutCache(ajax.POST, ajaxLogin, data, callback); 707} 708 709 710// Logica para edição de dados do cliente com base no tipo de login 711checkoutcustomer.enableEditByLoginType = function(loginType) { 712 loading.hide(); 713 if (loginType.data.data == true) { 714 var loginTitle = ''; 715 var loginHeader = ''; 716 var closeButton = true; 717 var backdrop = false; 718 var showRegister = false; 719 720 if (missingDocument) { 721 loginTitle = '<small>Faça login ou crie um token de acesso abaixo, para terminar seu cadastro.</small>'; 722 loginHeader = '<i class="fa fa-sign-in"></i>Ops! Seu cadastro está incompleto!'; 723 closeButton = false;
724 backdrop = true; 725 } 726 727 checkoutcustomer.showModalLogin(loginTitle, loginHeader, closeButton, backdrop, showRegister); 728 return; 729 } 730 // Caso o cliente não esteja logado como guest os campos são habilitados para edição 731 checkoutcustomer.enableEditForm(missingDocument); 732} 733 734checkoutcustomer.enableEditForm = function(missingDocument) { 735 var editButton = "#edit-customer"; 736 var registerButton = "#register-customer"; 737 var termsOfUseDiv = "#terms-of-use-div"; 738 739 checkoutcustomer.showPersonalValidating() 740 checkoutcustomer.showEmailValidating(); 741 checkoutcustomer.hideEmailValidatingButton(); 742 checkoutcustomer.hidePersonalValidated(); 743 checkoutcustomer.fillCustomerData(); 744 745 $(".validating-email input[name='email']").prop("disabled", true); 746 $(".validating-email-password input[name='email']").prop("disabled", true); 747 $(".validating-password-email input[name='password']").prop("disabled", true); 748 749 if (missingDocument == false) { 750 checkoutcustomer.disbledFieldsOnEdit(); 751 } 752 753 $(termsOfUseDiv).addClass("d-none"); 754 $(registerButton).addClass("d-none"); 755 $(editButton).removeClass("d-none"); 756 757 enableEdit = true; 758 checkout.stepEvent(1, 'login'); 759 760 address.hideAddressValidating(); 761 address.hideAddressValidated(); 762} 763 764// Preenche o formulario do cliente de acordo com seus dados 765checkoutcustomer.fillCustomerData = function() { 766 var personTab = "#fisica-tab"; 767 var companyTab = "#juridica-tab"; 768 var personType = window.checkoutPersonType.personType; 769 770 if (!customerLoadedData) { 771 customerLoadedData = checkoutcustomer.getCustomerStructureForTemplate(); 772 } else { 773 $(checkoutcustomer.emailInput).val(customerLoadedData.customer.email); 774 $(checkoutcustomer.emailPasswordInput).val(customerLoadedData.customer.email); 775 } 776 777 var tpl = template.getTemplate('cliente/checkoutclientecadastro', customerLoadedData); 778 $(".customer-form-content").html(tpl); 779 780 if (personType == 2) { 781 $(personTab).parent(".nav-item").removeClass("d-none"); 782 $(companyTab).parent(".nav-item").addClass("d-none"); 783 $(personTab).click(); 784 } else if (personType == 3) { 785 $(personTab).parent(".nav-item").addClass("d-none"); 786 $(companyTab).parent(".nav-item").removeClass("d-none"); 787 $(companyTab).click(); 788 } 789 790 if (customerLoadedData.customer.cpf != null && customerLoadedData.customer.cpf.length > 0) { 791 $(personTab).tab("show"); 792 $(companyTab).addClass("d-none"); 793 } else if (customerLoadedData.customer.cnpj != null && customerLoadedData.customer.cnpj.length > 0) { 794 $(companyTab).tab("show"); 795 $(personTab).addClass("d-none"); 796 } 797 798 masks.loadMasks(); 799 checkoutcustomer.subscribeWhatsAppPhoneListener(); 800} 801 802// Edita cliente 803checkoutcustomer.editCustomer = function() { 804 var selectorSubmit = "#edit-customer"; 805 var event = "click"; 806 807 $(document).on(event, selectorSubmit, function(e) { 808 var validCustomer = validator.isCustomerValid(); 809 if (validCustomer == false) { 810 ajaxutils.showAlertModal("", "Precisamos de algumas informações para editar seu cadastro <br>" + validator.customerErrorMsg, "Não conseguimos editar seu cadastro :("); 811 return; 812 } 813 814 var customer = checkoutcustomer.createCustomerObject(); 815 816 var phone = customer.phone ? customer.phone : customer.foreignPersonPhone; 817 var celphone = phone.replace(/\D/g, '').length == 11 ? phone : ''; 818 819 //TO DO Alterar origem 820 var data = { 821 act: "alterar", 822 origem: 12, 823 email: customer.email, 824 razao: customer.companyName, 825 cnpj: customer.companyCnpj, 826 ie: customer.companyIe, 827 isento: customer.companyIeExempt, 828 nome: customer.personName ? customer.personName : customer.foreignPersonName, 829 sobrenome: customer.personLastname ? customer.personLastname : customer.foreignPersonLastName, 830 cpf: customer.personCpf, 831 documentoEstrangeiro: customer.foreignPersonDocument, 832 telefone: phone, 833 celular: celphone, 834 dataNasc: null, 835 documentoEstrangeiroPais: customer.foreignPersonDocumentCountry, 836 nomeFantasia: customer.fantasyName, 837 im: customer.municipalityInscription, 838 rg: customer.rg, 839 dataNasc: customer.birthDate, 840 genero: customer.gender, 841 celular: customer.cellPhone, 842 origem: customer.origin, 843 tipoCompra: customer.purchaseType, 844 custom: customer.customFields 845 }; 846 847 loading.show(personalSelector); 848 ajax.enqueue(ajax.POST, ajaxCustomer, data, 'checkoutcustomer.handleCustomerRegister'); 849 850 $(document).trigger('checkout.customer.data.edited', [customer]); 851 }); 852} 853 854checkoutcustomer.areTermsOfUseAgreed = function() { 855 if (!$("#checktermosdeuso").is(":visible")) { 856 return true; 857 } 858 859 return $("#checktermosdeuso").is(":checked"); 860} 861 862// Define o nome do cliente a ser exibido 863checkoutcustomer.defineCustomerName = function(customerData) { 864 var customerName = 'Cliente'; 865 866 if (!helper.isEmpty(customerData.nome)) { 867 customerName = customerData.nome + " " + customerData.sobrenome; 868 } else if (!helper.isEmpty(customerData.fantasia)) { 869 customerName = customerData.fantasia; 870 } else if (!helper.isEmpty(customerData.razao)) { 871 customerName = customerData.razao; 872 } 873 874 return customerName; 875} 876 877checkoutcustomer.hidePersonalValidating = function() { 878 $(personalValidating).addClass("d-none"); 879} 880 881checkoutcustomer.showPersonalValidating = function() { 882 $(personalValidating).removeClass("d-none"); 883} 884 885checkoutcustomer.hidePersonalValidated = function() { 886 $(personalValidated).addClass("d-none"); 887} 888 889checkoutcustomer.showPersonalValidated = function() { 890 $(personalValidated).removeClass("d-none"); 891} 892 893checkoutcustomer.hideEmailValidating = function() { 894 $(emailValidating).addClass("d-none"); 895 $(emailPasswordValidating).addClass("d-none"); 896 $(passwordEmailValidating).addClass("d-none"); 897} 898 899checkoutcustomer.showEmailValidating = function() { 900 $(emailValidating).removeClass("d-none"); 901 $(emailPasswordValidating).removeClass("d-none"); 902} 903 904checkoutcustomer.hideAccessValidating = function() { 905 $(accessValidating).addClass("d-none"); 906} 907 908checkoutcustomer.showAccessValidating = function() { 909 $(accessValidating).removeClass("d-none"); 910} 911 912checkoutcustomer.hideEmailValidatingButton = function() { 913 var button = emailValidating + " button"; 914 $(button).addClass("d-none"); 915 916 var buttonPassword = emailPasswordValidating + " button"; 917 $(buttonPassword).addClass("d-none"); 918 919 var buttonRegister = emailPasswordValidating + " span"; 920 $(buttonRegister).addClass("d-none"); 921} 922 923checkoutcustomer.disbledFieldsOnEdit = function() { 924 $(".validating-email input[name='email']").prop("disabled", true); 925 $(".customer-form input[name='personCpf']").prop("disabled", true); 926 $(".customer-form input[name='companyCnpj']").prop('disabled', true); 927 $(".customer-form input[name='companyIe']").prop('disabled', true); 928 $(".customer-form input[name='companyIeExempt']").prop('disabled', true); 929} 930 931checkoutcustomer.showModalLogin = function(loginTitle, loginHeader, closeButton, backdrop, showRegister) { 932 loginTitle = loginTitle || null; 933 loginHeader = loginHeader || 'Faça seu acesso'; 934 closeButton = (typeof closeButton !== 'undefined') ? closeButton : true; 935 backdrop = (typeof backdrop !== 'undefined') ? backdrop : true; 936 showRegister = (typeof showRegister !== 'undefined') ? showRegister : true; 937 938 $('.modal-dialog').parent().remove(); 939 $('.modal').remove(); 940 $('[class^="modal"].fade').remove(); 941 $('body').removeClass("modal-open"); 942 943 var data = { 944 showRegister: showRegister 945 }; 946 var modalLoginTemplate = template.getTemplate('cliente/checkoutmodallogin', data); 947 ajaxutils.showAlertModal(loginTitle, modalLoginTemplate, loginHeader, backdrop, closeButton); 948} 949 950checkoutcustomer.showNeedLogin = function() { 951 const isApp = window.location.hostname.includes('app.'); 952 953 if (isApp) { 954 return; 955 } 956 957 var header = 'Atenção!'; 958 var title = 'Acesso não permitido'; 959 var message = 'Para prosseguir com acesso, por favor, faça o login na sua conta.'; 960 961 $('.modal-dialog').parent().remove(); 962 $('.modal').remove(); 963 $('[class^="modal"].fade').remove(); 964 $('body').removeClass("modal-open"); 965 966 ajaxutils.showAlertModal(title, message, header, null, true); 967} 968 969checkoutcustomer.handleLogin = function(response) { 970 checkoutcustomer.resetWarningContainers(); 971 972 if (response.error === true) { 973 errorMessages = response.message; 974 975 if (errorMessages.failedLoginMessage) { 976 $(errorLabelSelector).html(errorMessages.failedLoginMessage); 977 $(errorLabelContainerSelector).removeClass("hidden"); 978 } 979 980 if (errorMessages.securityLoginMessage) { 981 $(securityErrorLabelSelector).html(errorMessages.securityLoginMessage); 982 $(securityErrorLabelContainerSelector).removeClass("hidden"); 983 } 984 985 return; 986 } 987 988 var data = response.data.data; 989 990 checkoutcustomer.handleLoginResponse(data); 991} 992 993checkoutcustomer.handleLoginResponse = function(data) { 994 if (data === true) { 995 helper.closeModal(); 996 997 if (!window.isCacheable) { 998 location.reload(); 999 return; 1000 } else { 1001 $(document).trigger("ajaxcache.needupdate"); 1002 } 1003 } 1004 1005 if (data.redirect) { 1006 helper.redirect(data.redirect); 1007 } 1008} 1009 1010checkoutcustomer.handleAccesKey = function(response) { 1011 if (response.error === true) { 1012 $(errorLabelSelector).html('Oops, email não está cadastrado'); 1013 $(errorLabelContainerSelector).removeClass("hidden"); 1014 return; 1015 } 1016 1017 if (response.data.data == true) { 1018 // Go to step4 1019 $('[data-stage-command=\'4\']').trigger('click'); 1020 $(okLabelSelector).html('Em alguns minutos chegará em seu email o token de acesso'); 1021 return; 1022 } 1023} 1024 1025checkoutcustomer.handleLoginToken = function(response) { 1026 checkoutcustomer.resetWarningContainers(); 1027 1028 if (response.error === true) { 1029 errorMessages = response.message; 1030 1031 if (errorMessages.failedLoginMessage) { 1032 $(errorLabelSelector).html(errorMessages.failedLoginMessage); 1033 $(errorLabelContainerSelector).removeClass("hidden"); 1034 } 1035 1036 if (errorMessages.securityLoginMessage) { 1037 $(securityErrorLabelSelector).html(errorMessages.securityLoginMessage); 1038 $(securityErrorLabelContainerSelector).removeClass("hidden"); 1039 } 1040 1041 if (errorMessages.emailtokenlogin) { 1042 $(errorLabelSelector).html(errorMessages.emailtokenlogin); 1043 $(errorLabelContainerSelector).removeClass("hidden"); 1044 } 1045 1046 return; 1047 } 1048 1049 var data = response.data.data; 1050 1051 checkoutcustomer.handleLoginResponse(data); 1052} 1053 1054checkoutcustomer.showCensoredEmailInEmailContainer = function(emailCensurado) { 1055 const emailContainer = $('#email-container'); 1056 1057 if (emailContainer.length) { 1058 emailContainer.text(emailCensurado); 1059 } 1060} 1061 1062checkoutcustomer.handlePasswordToken = function(response) { 1063 if (response.error === true) { 1064 $(errorLabelSelector).html(response.message); 1065 $(errorLabelContainerSelector).removeClass("hidden"); 1066 return; 1067 } 1068 1069 if (response.data.data.success == true) { 1070 checkoutcustomer.showCensoredEmailInEmailContainer(response.data.data.emailCensurado); 1071 helper.inputValueCopy(); 1072 $('[data-stage-command=\'6\']').trigger('click'); 1073 return; 1074 } 1075} 1076 1077checkoutcustomer.handlePasswordChange = function(response) { 1078 checkoutcustomer.resetWarningContainers(); 1079 1080 if (response.error == true) { 1081 errorMessages = response.message; 1082 1083 if (errorMessages.failedLoginMessage) { 1084 $(errorLabelSelector).html(errorMessages.failedLoginMessage); 1085 $(errorLabelContainerSelector).removeClass("hidden"); 1086 } 1087 1088 if (errorMessages.securityLoginMessage) { 1089 $(securityErrorLabelSelector).html(errorMessages.securityLoginMessage); 1090 $(securityErrorLabelContainerSelector).removeClass("hidden"); 1091 } 1092 1093 checkoutcustomer.showCensoredEmailInEmailContainer(response.data.data.emailCensurado); 1094 1095 return; 1096 } 1097 1098 var data = response.data.data; 1099 1100 checkoutcustomer.handleLoginResponse(data); 1101} 1102 1103checkoutcustomer.handleOauthLogin = function(response) { 1104 helper.closeModal(); 1105 if (response.error) { 1106 errorMessages = response.message; 1107 1108 if (errorMessages.securityLoginMessage) { 1109 ajaxutils.showModal("", "Não foi possível realizar o acesso", errorMessages.securityLoginMessage); 1110 } else { 1111 ajaxutils.showModal("Não foi possível realizar o acesso", errorMessages); 1112 } 1113 1114 return; 1115 } 1116 1117 if (!response.data || !response.data.data) { 1118 console.log('sem retorno'); 1119 return; 1120 } 1121 1122 if (response.data.data.redirect) { 1123 location.href = response.data.data.url; 1124 return; 1125 } 1126 1127 window.localStorage.setItem("needUpdate", true); 1128 location.reload(); 1129} 1130 1131// Envia eventos de inÃcio de cadastro 1132checkoutcustomer.leadTracker = function() { 1133 if (typeof fbq !== 'undefined') { 1134 fbq('track', 'Lead'); 1135 } 1136} 1137 1138// Envia eventos de confirmação de cadastro 1139checkoutcustomer.registerTracker = function() { 1140 if (typeof fbq !== 'undefined') { 1141 fbq('track', 'CompleteRegistration', {currency: 'BRL', value: checkout.order.total}); 1142 } 1143} 1144 1145checkoutcustomer.socialNetworksLoginListener = function() { 1146 $(document).ready(function() { 1147 if ($('.g_id_signin').length > 0) { 1148 $('.social-login').addClass('row'); 1149 return; 1150 } 1151 1152 $('.fb-login-button').removeClass('col-sm-6').addClass('col-12'); 1153 $('.google-login-button').addClass('hide'); 1154 }); 1155} 1156 1157checkoutcustomer.subscribeWhatsAppPhoneListener = function() { 1158 var phones = $('.customer-form .phone'); 1159 1160 phones.each(function() { 1161 $(this).on('keyup', function(e) { 1162 var subscribeWhatsApp = $('[subscribe-whatsApp]'); 1163 var subscribeWhatsAppCheckBox = $(".customer-form input[name='subscribeWhatsApp']"); 1164 1165 var phone = $(this).val(); 1166 phone = phone.replace(/\D/g, ''); 1167 1168 if (phone.length == 11) { 1169 if (subscribeWhatsApp.hasClass('d-none')) { 1170 subscribeWhatsApp.removeClass('d-none'); 1171 } 1172 1173 if (!subscribeWhatsAppCheckBox.is(':checked')) { 1174 $(".customer-form input[name='subscribeWhatsApp']").click(); 1175 } 1176 } else { 1177 if (!subscribeWhatsApp.hasClass('d-none')) { 1178 subscribeWhatsApp.addClass('d-none'); 1179 } 1180 1181 if (subscribeWhatsAppCheckBox.is(':checked')) { 1182 $(".customer-form input[name='subscribeWhatsApp']").click(); 1183 } 1184 } 1185 }); 1186 }); 1187} 1188 1189checkoutcustomer.resetWarningContainers = function() { 1190 $(errorLabelSelector).html(''); 1191 $(errorLabelContainerSelector).addClass("hidden"); 1192 $(securityErrorLabelSelector).html(''); 1193 $(securityErrorLabelContainerSelector).addClass("hidden"); 1194} 1195 1196$(function(){ 1197 checkoutcustomer.changeEmailEvent(); 1198 checkoutcustomer.registerCustomer(); 1199 checkoutcustomer.editCustomer(); 1200 checkoutcustomer.socialNetworksLoginListener(); 1201});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.