//url da loja var urlSSL = 'https://www.ervanariacentral.com.br/'; //funcoes javascript function aplicar_metodo_entrega_checkout(meio){ if(meio==''){ return false; } console.log('Meio de entrega: '+meio+'!'); var comentario = $('#comentario_pedido').val(); if (typeof comentario == 'undefined') { var comentario = ''; } $.ajax({ type: "POST", url: urlSSL+"index.php?route=checkout/shipping_method/save", data: {shipping_method:meio,comment:comentario}, dataType: 'JSON', }).done(function( data ) { if(typeof data.redirect !== 'undefined'){ location.href = data.redirect; return false; }else if(typeof data.error !== 'undefined'){ alerta_bootbox(data.error.warning); desbloquear_tela_checkout(); return false; }else{ //carrega o carrinho carregar_carrinho_checkout(); //aplica novamente o metodo de pagamento se selecionado var meio_pagamento = qual_metodo_pagamento_checkout(); if(meio_pagamento){ //tela de pagamento carregar_pagamento_checkout(meio_pagamento); }else{ //tela de produtos $.ajax({ type: "GET", url: urlSSL+"index.php?route=checkout/compraexpress/ver_itens_html", dataType: 'html', }).done(function( html ) { var div = $('#tabela-produtos'); div.html(html); }); } } }); } function tipo_cliente_cliente(tipo,zona='todas'){ //remove os campos antes de adicionar novos $('.custom-field').remove(); //pega o tipo de cliente selecionado var $radios = $('input:radio[name=tipo_pessoa]'); if($radios.is(':checked') === false) { $radios.filter('[value='+tipo+']').prop('checked', true); } //campos extras html cliente if(zona=='todas' || zona=='cliente'){ $.ajax({ type: "POST", url: urlSSL+"index.php?route=account/registroexpress/campos_extras_cliente", dataType: 'html', data: {grupo: tipo} }).done(function( html ) { $('#campos_extras_cliente').html(html); }); } //campos extras html endereco if(zona=='todas' || zona=='endereco'){ var id_endereco = $('#endereco_inicial').val(); $.ajax({ type: "POST", url: urlSSL+"index.php?route=account/registroexpress/campos_extras_endereco&endereco_id="+id_endereco, dataType: 'html', data: {grupo: tipo} }).done(function( html ) { $('#campos_extras_endereco').html(html); }); } } /* function buscar_endereco_cadastro(){ var EstadosArray = []; EstadosArray["AC"] = 440; EstadosArray["AL"] = 441; EstadosArray["AP"] = 442; EstadosArray["AM"] = 443; EstadosArray["BA"] = 444; EstadosArray["CE"] = 445; EstadosArray["DF"] = 446; EstadosArray["ES"] = 447; EstadosArray["GO"] = 448; EstadosArray["MA"] = 449; EstadosArray["MT"] = 450; EstadosArray["MS"] = 451; EstadosArray["MG"] = 452; EstadosArray["PA"] = 453; EstadosArray["PB"] = 454; EstadosArray["PR"] = 455; EstadosArray["PE"] = 456; EstadosArray["PI"] = 457; EstadosArray["RJ"] = 458; EstadosArray["RN"] = 459; EstadosArray["RS"] = 460; EstadosArray["RO"] = 461; EstadosArray["RR"] = 462; EstadosArray["SC"] = 463; EstadosArray["SP"] = 464; EstadosArray["SE"] = 465; EstadosArray["TO"] = 466; var cep = $("#address input[name='cep']").val(); var s = (cep).replace(/\D/g,''); var tam=(s).length; if(tam==8){ $.getScript(urlSSL+"api_cep.php?formato=javascript&cep="+cep, function(){ if(resultadoCEP["resultado"] != 0){ console.log(resultadoCEP); $("#address input[name='logradouro']").val(unescape(resultadoCEP["tipo_logradouro"]).toUpperCase()+""+unescape(resultadoCEP["logradouro"])); $("#address input[name='bairro']").val(unescape(resultadoCEP["bairro"])); $("#address input[name='cidade']").val(unescape(resultadoCEP["cidade"])); $("#address select[name='uf']").val(EstadosArray[resultadoCEP["uf"]]).trigger('click'); } }); } } */ function buscar_endereco_cadastro() { let EstadosArray = []; EstadosArray["AC"] = 440; EstadosArray["AL"] = 441; EstadosArray["AP"] = 442; EstadosArray["AM"] = 443; EstadosArray["BA"] = 444; EstadosArray["CE"] = 445; EstadosArray["DF"] = 446; EstadosArray["ES"] = 447; EstadosArray["GO"] = 448; EstadosArray["MA"] = 449; EstadosArray["MT"] = 450; EstadosArray["MS"] = 451; EstadosArray["MG"] = 452; EstadosArray["PA"] = 453; EstadosArray["PB"] = 454; EstadosArray["PR"] = 455; EstadosArray["PE"] = 456; EstadosArray["PI"] = 457; EstadosArray["RJ"] = 458; EstadosArray["RN"] = 459; EstadosArray["RS"] = 460; EstadosArray["RO"] = 461; EstadosArray["RR"] = 462; EstadosArray["SC"] = 463; EstadosArray["SP"] = 464; EstadosArray["SE"] = 465; EstadosArray["TO"] = 466; let cep = $('#address input[name=\'cep\']').val().replace(/\D/g,''); if (cep.length == 8) { bloquear_tela_checkout(); $.getScript(urlSSL +'api_cep.php?formato=javascript&cep='+ cep, function() { if (resultadoCEP.resultado != 0) { //console.log(resultadoCEP); $('#address input[name=\'logradouro\']').val(unescape(resultadoCEP.tipo_logradouro).toUpperCase() +''+ unescape(resultadoCEP.logradouro)); $('#address input[name=\'bairro\']').val(unescape(resultadoCEP.bairro)); $('#address input[name=\'cidade\']').val(unescape(resultadoCEP.cidade)); $('#address .country ul.sbOptions > li a[rel="30"]').trigger('click'); setTimeout(function() { $('#address .state ul.sbOptions > li a[rel="'+ EstadosArray[resultadoCEP.uf] +'"]').trigger('click'); }, 500); $('#address input[name=\'custom_field_endereco[1]\']').focus(); } else { if (confirm('CEP não encontrado! Deseja informar outro?') == true) $('#address :input').val(''), $('input[name=\'cep\']').focus(); } desbloquear_tela_checkout(); }); } else { $('#address :input:not(input[name=\'cep\'])').val(''); } } function alerta_bootbox(alerta){ if (typeof bootbox.dialog !== "undefined") { bootbox.dialog({ message: alerta, title: "Ops", }); }else{ alert(alerta); } } function bloquear_tela_checkout(){ if (typeof $.blockUI !== "undefined") { $.blockUI({ message: '',css: { border: '0px solid #000', 'background-color': 'transparent', padding: '10px'}}); } } function desbloquear_tela_checkout(){ if (typeof $.blockUI !== "undefined") { $.unblockUI(); $('.blockUI').remove(); } } function bloquearteladiv(div){ $('#'+div).block({message: ''}); } function sair_checkout_express(){ bootbox.confirm("Confirma sair da loja?", function(result) { if(result==true){ $.ajax({ type: "POST", url: urlSSL+"index.php?route=checkout/compraexpress/sair", dataType: 'html', }).done(function( html ) { location.href = urlSSL+"index.php?route=account/logout"; }); } }); return true; } function abrir_tela_checkout(url,titulo){ if($.pgwModal('isOpen')){ $.pgwModal('close'); } $.pgwModal({ url: url, title : titulo, loadingContent: '

', closable: true, titleBar: true, closeOnBackgroundClick: false, maxWidth : 700 }); } function carregar_checkout_express(){ $.ajax({ url: urlSSL+'index.php?route=checkout/compraexpress/checkout', dataType: 'html', success: function(html) { $('#html-compraexpress').html(html); desbloquear_tela_checkout(); }, error: function(xhr, ajaxOptions, thrownError) { alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); } }); } function remover_carrinho(key){ $.ajax({ url: 'index.php?route=checkout/cart/remove', type: 'post', data: 'key=' + key, dataType: 'json', beforeSend: function() { $('#cart > button').button('loading'); }, complete: function() { $('#cart > button').button('reset'); }, success: function(json) { setTimeout(function() { $('#cart > button').html(' ' + json['total'] + ''); }, 100); carregar_carrinho_checkout(); carregar_tela_produtos_checkout(); setTimeout(function() { window.location.reload(true); }, 500); } }); } function remover_voucher(key){ $.ajax({ url: 'index.php?route=checkout/cart/remove', type: 'post', data: 'key=' + key, dataType: 'json', beforeSend: function() { $('#cart > button').button('loading'); }, complete: function() { $('#cart > button').button('reset'); }, success: function(json) { setTimeout(function () { $('#cart > button').html(' ' + json['total'] + ''); }, 100); carregar_carrinho_checkout(); carregar_tela_produtos_checkout(); } }); } function carregar_tela_produtos_checkout(){ $.ajax({ type: "GET", url: urlSSL+"index.php?route=checkout/compraexpress/ver_itens_html", dataType: 'html', }).done(function( html ) { var div = $('#tabela-produtos'); div.html(html); }); } function carregar_endereco_cliente_json(endereco,tipo,zona){ $('#endereco_inicial').val(endereco); $.ajax({ type: "GET", url: urlSSL+"index.php?route=checkout/compraexpress/dados_endereco_json&id="+endereco, dataType: 'JSON', }).done(function( dados ) { console.log(dados); tipo_cliente_cliente(tipo,zona); if(dados.id){ $('#idendereco_e').val(dados.id); $('#nome_completo_e').val(dados.nome+' '+dados.sobrenome); $('#cep_e').val(dados.cep); $('#logradouro_e').val(dados.logradouro); $('#bairro_e').val(dados.bairro); $('#cidade_e').val(dados.cidade); $('#uf_e').val(dados.uf); $('#pais_e').val(dados.pais); $('#acao_endereco').val('atualizar'); }else{ $('#endereco_inicial').val(''); $('#idendereco_e').val(''); $('#nome_completo_e').val(''); $('#cep_e').val(''); $('#logradouro_e').val(''); $('#bairro_e').val(''); $('#cidade_e').val(''); $('#uf_e').val(''); $('#acao_endereco').val('adicionar'); } }); } function carregarEstados(estado,ufe){ $.ajax({ type: "GET", url: urlSSL+"index.php?route=account/registroexpress/estados", data: {pais:estado}, dataType: 'json', }).done(function( dados ) { var estados = ''; $.each(dados, function(key,val) { estados += ''; }); $('#'+ufe).html(estados); }); } function ativar_mostrar_endereco(tipo){ $('.lista_enderecos').hide(); $('#endereco-'+tipo).show(); $('.botoes_enderecos').removeClass('active'); $('.'+tipo).addClass('active'); } function recupersenha(form){ var dados = $(form).serialize(); console.log(dados); $.ajax({ type: "POST", url: urlSSL+"index.php?route=checkout/compraexpress/atualizarsenhaemail", dataType: 'json', data: dados, beforeSend: function() { //bloquear_tela_checkout(); }, }).done(function( dados ) { console.log(dados); if(dados.erro==true){ $('#div-rec-msg').html(''); }else{ $('#div-rec-msg').html(''); setTimeout(function() { $.pgwModal('close'); }, 1000); } }); return false; } function check_metodo_pagamento_checkout(){ var meio_pagamento = qual_metodo_pagamento_checkout(); if(meio_pagamento){ return true; }else{ alerta_bootbox("Selecione primeiro uma forma de pagamento!"); return false; } } function logincompraexpressaviso(form){ var dados = $(form).serialize(); console.log(dados); if(!$(form).valid()){ return false; } $.ajax({ type: "POST", url: urlSSL+"index.php?route=checkout/compraexpress/entrar", dataType: 'html', data: dados, beforeSend: function() { bloquear_tela_checkout(); }, }).done(function( html ) { if(html==0){ $('#div-login-msg-aviso-modal').html(''); desbloquear_tela_checkout(); }else{ $.pgwModal('close'); carregar_checkout_express(); } }); return false; } function aplicar_metodo_pagamento_checkout(meio){ //pega o metodo de entrega selecionado var meio_entrega = qual_metodo_entrega_checkout(); //verifica se o produto tem um meio de entrega selecionado ou e digital var produto_digital = $('input[name="produto_digital"]').val(); if(produto_digital=='false' && meio_entrega==false){ alerta_bootbox("Selecione primeiro o meio de entrega para poder selecionar a forma de pagamento!"); if (screen.width < 1200) {$("html, body").animate({scrollTop: 800}, 600);} limpar_metodo_pagamento_checkout(); return false; } //bloqueia se vazio if(meio==''){ return false; } //aplica e salva o metodo de pagamento console.log('Metodo de pagamento: '+meio+'!'); var comentario = $('#comentario_pedido').val(); if (typeof comentario == 'undefined') { var comentario = ''; } $.ajax({ type: "POST", url: urlSSL+"index.php?route=checkout/payment_method/save", data: {payment_method:meio,agree:1,comment:comentario}, dataType: 'html', }).done(function( html ) { //salva e carrega $('#meio_selecionado_express').val(meio); carregar_pagamento_checkout(meio); }); } function carregar_pagamento_checkout(meio){ if(meio==''){ return false; } $(":radio[value="+meio+"]").prop('checked',true); var idcliente = $('#cliente_id').val(); var clientehash = $('#cliente_hash').val(); bloquear_tela_checkout(); //carrega a tela de pagamento $.ajax({ type: "GET", url: urlSSL+"index.php?route=checkout/confirm", data: {id:idcliente,hash:clientehash}, dataType: 'html', }).done(function( html ) { //div pagamento var div = $('#html-detalhes-como-pagar'); div.html(html); //desbloqueia a tela desbloquear_tela_checkout(); //foca o metodo de pagamento $('html, body').animate({ scrollTop: $("#html-detalhes-como-pagar").offset().top }, 3000); carregar_carrinho_checkout(); }); } function carregar_carrinho_checkout(){ $.ajax({ type: "GET", url: urlSSL+"index.php?route=common/cart/info&express=true", dataType: 'HTML', }).done(function(html) { console.log('Carrinho topo atualizado!'); //$('#cart, #cart_block').replaceWith(html); $('#minicart .modal-body .load-data').load('index.php?route=extension/minicart/minicart/info .modal-body .load-data'); $('#loadproducts').load('index.php?route=extension/minicart/minicart/loadproducts'); }); } $(document).on('click', '.box-cart', function() { $('#minicart').modal('show'); }); function qual_metodo_pagamento_checkout(){ var selectedValue = false; var radios = document.getElementsByName("meios_pagamento"); for(var i = 0; i < radios.length; i++) { if(radios[i].checked) selectedValue = radios[i].value; } return selectedValue; } function limpar_metodo_pagamento_checkout(){ var radios = document.getElementsByName("meios_pagamento"); for(var i = 0; i < radios.length; i++) { radios[i].checked = false; } return true; } function qual_metodo_entrega_checkout(){ var selectedValue = false; var radios = document.getElementsByName("meios_entrega"); for(var i = 0; i < radios.length; i++) { if(radios[i].checked) selectedValue = radios[i].value; } return selectedValue; } //detectar acoes do carrinho $( document ).ajaxSuccess(function( event, xhr, settings ) { if (typeof settings.url !== 'undefined' && typeof settings.data !== 'undefined') { console.log(settings.url); if(settings.url=='index.php?route=checkout/cart/remove' || settings.url=='checkout/cart/remove'){ carregar_tela_produtos_checkout(); } } }); //login facebook //mascaras javascript pura function mascara(o,f){ v_obj=o v_fun=f setTimeout("execmascara()",1) } function execmascara(){ if(v_fun=='telefone') v_obj.value=telefone(v_obj.value); if(v_fun=='soNumeros') v_obj.value=soNumeros(v_obj.value); if(v_fun=='cpf') v_obj.value=cpf(v_obj.value); if(v_fun=='cnpj') v_obj.value=cnpj(v_obj.value); if(v_fun=='cpfcnpj') v_obj.value=cpfCnpj(v_obj.value); if(v_fun=='cep') v_obj.value=cep(v_obj.value); } function cpfCnpj(v){ v=v.replace(/\D/g,"") if (v.length <= 11) { v=v.replace(/(\d{3})(\d)/,"$1.$2") v=v.replace(/(\d{3})(\d)/,"$1.$2") v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") } else { v=v.replace(/^(\d{2})(\d)/,"$1.$2") v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") v=v.replace(/\.(\d{3})(\d)/,".$1/$2") v=v.replace(/(\d{4})(\d)/,"$1-$2") } return v } function soNumeros(v){ return v.replace(/\D/g,"") } function telefone(v){ v=v.replace(/\D/g,"") v=v.replace(/^(\d\d)(\d)/g,"($1)$2") return v } function cpf(v){ v=v.substr(0,14); v=v.replace(/\D/g,"") v=v.replace(/(\d{3})(\d)/,"$1.$2") v=v.replace(/(\d{3})(\d)/,"$1.$2") v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") return v } function cnpj(v){ v=v.substr(0,18); v=v.replace(/\D/g,"") v=v.replace(/^(\d{2})(\d)/,"$1.$2") v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") v=v.replace(/\.(\d{3})(\d)/,".$1/$2") v=v.replace(/(\d{4})(\d)/,"$1-$2") return v } function cep(v){ v=v.replace(/[^1234567890-]/g,""); v=v.replace(/^(\d{5})(\d)/,"$1-$2") return v }