', type: 'warning', showCancelButton: true, confirmButtonColor: '#61a642', cancelButtonColor: '#d33', confirmButtonText: 'Eu aceito', cancelButtonText: 'Não concordo', }).then(function(result){ if (result.value) { swal({ title : 'Produto Adicionado Com Sucesso!', html: '
Para poder realizar o calculo do frete escolha seu numero e a quantidade desejada. '); $('#button-quote_product').button('reset'); clearTimeout(clear_time); clear_time = setTimeout(function(){ $('#modal-shipping').fadeOut('slow', function(){ $(this).empty(); $(this).show(); }); }, 5000); } else { $.ajax({ url: 'index.php?route=module/shipping/simulate', type: 'post', data: params, dataType: 'json', beforeSend: function () { $('#button-quote_product').button('loading'); }, complete: function () { $('#button-quote_product').button('reset'); }, success: function (json) { $('#modal-shipping').empty(); $('#shipping-error').empty(); $('.alert, .text-danger, .simulate_shipping_methods, #shipping-error').remove(); if (json['error']) { if (json['error']['warning']) { $('#shipping-error').remove(); $('.postcode-inputs').append('
' + json['error']['warning'] + '
'); } if (json['error']['postcode']) { $('.postcode-inputs').append('
' + json['error']['postcode'] + '
'); } } if (json['shipping_method']) { html = '
'; html += ''; html_error = ''; for (i in json['shipping_method']) { if (!json['shipping_method'][i]['error']) { for (j in json['shipping_method'][i]['quote']) { if(j == 'frete_rapido'){ for (k in json['shipping_method'][i]['quote'][j]) { html += '
'; html += ''; html += json['shipping_method'][i]['quote'][j][k]['title'] + ' - ' + json['shipping_method'][i]['quote'][j][k]['text']; html += ' '+json['shipping_method'][i]['quote'][j][k]['delivery_time']+' '; html += ' '; html += '
'; if(json['shipping_method'][i]['quote'][j][k]['info']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['info']+' '; } } } else if (j == 'mandae'){ for (k in json['shipping_method'][i]['quote'][j]) { html += '
'; html += ''; html += json['shipping_method'][i]['quote'][j][k]['title'] + ' - ' + json['shipping_method'][i]['quote'][j][k]['text']; html += ' '+json['shipping_method'][i]['quote'][j][k]['delivery_time']+' '; html += ' '; html += '
'; if(json['shipping_method'][i]['quote'][j][k]['info']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['info']+' '; } if(json['shipping_method'][i]['quote'][j][k]['error']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['error']+' '; } } } else if (j == 'jadlog_api'){ for (k in json['shipping_method'][i]['quote'][j]) { html += '
'; html += ''; html += json['shipping_method'][i]['quote'][j][k]['title'] + ' - ' + json['shipping_method'][i]['quote'][j][k]['text']; html += ' '+json['shipping_method'][i]['quote'][j][k]['delivery_time']+' '; html += ' '; html += '
'; if(json['shipping_method'][i]['quote'][j][k]['info']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['info']+' '; } if(json['shipping_method'][i]['quote'][j][k]['error']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['error']+' '; } } } else if (j == 'melhor_envio'){ for (k in json['shipping_method'][i]['quote'][j]) { html += '
'; html += ''; html += json['shipping_method'][i]['quote'][j][k]['title'] + ' - ' + json['shipping_method'][i]['quote'][j][k]['text']; html += ' '+json['shipping_method'][i]['quote'][j][k]['delivery_time']+' '; html += ' '; html += '
'; if(json['shipping_method'][i]['quote'][j][k]['info']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['info']+' '; } if(json['shipping_method'][i]['quote'][j][k]['error']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['error']+' '; } } }else if (j == 'rodoe'){ for (k in json['shipping_method'][i]['quote'][j]) { html += '
'; html += ''; html += json['shipping_method'][i]['quote'][j][k]['title'] + ' - ' + json['shipping_method'][i]['quote'][j][k]['text']; html += ' '+json['shipping_method'][i]['quote'][j][k]['delivery_time']+' '; html += ' '; html += '
'; if(json['shipping_method'][i]['quote'][j][k]['info']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['info']+' '; } if(json['shipping_method'][i]['quote'][j][k]['error']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['error']+' '; } } } else if (j == 'frenet'){ for (k in json['shipping_method'][i]['quote'][j]) { html += '
'; html += ''; html += json['shipping_method'][i]['quote'][j][k]['title'] + ' - ' + json['shipping_method'][i]['quote'][j][k]['text']; html += ' '+json['shipping_method'][i]['quote'][j][k]['delivery_time']+' '; html += ' '; html += '
'; if(json['shipping_method'][i]['quote'][j][k]['info']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['info']+' '; } if(json['shipping_method'][i]['quote'][j][k]['error']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['error']+' '; } } } else if (j == 'data_frete') { for (k in json['shipping_method'][i]['quote'][j]) { html += '
'; html += ''; html += json['shipping_method'][i]['quote'][j][k]['title'] + ' - ' + json['shipping_method'][i]['quote'][j][k]['text']; html += ' '+json['shipping_method'][i]['quote'][j][k]['delivery_time']+' '; html += ' '; html += '
'; if(json['shipping_method'][i]['quote'][j][k]['info']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['info']+' '; } if(json['shipping_method'][i]['quote'][j][k]['error']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['error']+' '; } } } else if (j == 'intelipost') { for (k in json['shipping_method'][i]['quote'][j]) { html += '
'; html += ''; html += json['shipping_method'][i]['quote'][j][k]['title'] + ' - ' + json['shipping_method'][i]['quote'][j][k]['text']; html += ' '+json['shipping_method'][i]['quote'][j][k]['delivery_time']+' '; html += ' '; html += '
'; if(json['shipping_method'][i]['quote'][j][k]['info']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['info']+' '; } if(json['shipping_method'][i]['quote'][j][k]['error']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['error']+' '; } } } else if (j == 'smart_envios') { for (k in json['shipping_method'][i]['quote'][j]) { html += '
'; html += ''; html += json['shipping_method'][i]['quote'][j][k]['title'] + ' - ' + json['shipping_method'][i]['quote'][j][k]['text']; html += ' '+json['shipping_method'][i]['quote'][j][k]['delivery_time']+' '; html += ' '; html += '
'; if(json['shipping_method'][i]['quote'][j][k]['info']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['info']+' '; } if(json['shipping_method'][i]['quote'][j][k]['error']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['error']+' '; } } } else if (j == 'kangu') { for (k in json['shipping_method'][i]['quote'][j]) { if (json['shipping_method'][i]['quote'][j][k]['title'] && json['shipping_method'][i]['quote'][j][k]['text'] && json['shipping_method'][i]['quote'][j][k]['delivery_time']){ html += '
'; html += ''; html += json['shipping_method'][i]['quote'][j][k]['title'] + ' - ' + json['shipping_method'][i]['quote'][j][k]['text']; html += ' '+json['shipping_method'][i]['quote'][j][k]['delivery_time']+' '; html += ' '; html += '
'; if(json['shipping_method'][i]['quote'][j][k]['info']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['info']+' '; } if(json['shipping_method'][i]['quote'][j][k]['error']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['error']+' '; } } } } else if (j == 'rede_sul' || j == 'ipost') { for (k in json['shipping_method'][i]['quote'][j]) { html += '
'; html += ''; html += json['shipping_method'][i]['quote'][j][k]['title'] + ' - ' + json['shipping_method'][i]['quote'][j][k]['text']; html += ' '+json['shipping_method'][i]['quote'][j][k]['delivery_time']+' '; html += ' '; html += '
'; if(json['shipping_method'][i]['quote'][j][k]['info']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['info']+' '; } if(json['shipping_method'][i]['quote'][j][k]['error']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['error']+' '; } } } else if (j == 'mandou_chegou') { for (k in json['shipping_method'][i]['quote'][j]) { html += '
'; html += ''; html += json['shipping_method'][i]['quote'][j][k]['title'] + ' - ' + json['shipping_method'][i]['quote'][j][k]['text']; html += ' '+json['shipping_method'][i]['quote'][j][k]['delivery_time']+' '; html += ' '; html += '
'; if(json['shipping_method'][i]['quote'][j][k]['info']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['info']+' '; } if(json['shipping_method'][i]['quote'][j][k]['error']){ html += '
'+json['shipping_method'][i]['quote'][j][k]['error']+' '; } } } else { html += '
'; html += ''; html += json['shipping_method'][i]['quote'][j]['title'] + ' - ' + json['shipping_method'][i]['quote'][j]['text']; html += ' '+json['shipping_method'][j]['delivery_time']+' '; html += ' '; html += '
'; if(json['shipping_method'][j]['info']){ html += '
'+json['shipping_method'][j]['info']+' '; } if(json['shipping_method'][i]['quote'][j]['code'] == 'pickup.pickup'){ for (k in json['shipping_method'][i]['locations']){ html += '
' + json['shipping_method'][i]['locations'][k]['address'] + ' '; } } } } } else { if ((i == 'sedex' || i == 'pac') && html_error.search(json['shipping_method'][i]['quote'][i]['msgErro']) == -1) { if (json['shipping_method']['sedex'] == undefined || json['shipping_method']['pac'] == undefined) { html_error += '
' + json['shipping_method'][i]['quote'][i]['msgErro'] + '
'; } else if (json['shipping_method']['sedex']['error'] && json['shipping_method']['pac']['error']) { html_error += '
' + json['shipping_method'][i]['quote'][i]['msgErro'] + '
'; } } else if (i === 'mandae' || i === 'carriersapí' && i != 'pickup') { console.log(json['shipping_method'][i]['error']); html += '
'; html += '
'; if(json['shipping_method'][i]['error']){ html += ' '+json['shipping_method'][i]['error']+'
'; html += ' Serviços Mandaê temporariamente indisponivel
'; } html += ''; html += '
'; } else if (i != 'sedex' && i != 'pac' && i != 'mandae' && i != 'carriersapí') { html_error += '
' + json['shipping_method'][i]['quote'][i]['msgErro'] + '
'; } } } html += html_error; html += '
'; $(html).insertAfter('.postcode-inputs'); } $('.product-shipping-form .simulate_shipping_methods .close-popup, .product-shipping-form #shipping-error .close-popup').on('click', function(){ $('.product-shipping-form .simulate_shipping_methods, .product-shipping-form #shipping-error').fadeOut('fast', function(){ $(this).remove(); }); }); }, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log(XMLHttpRequest.responseText); } }); } }); $('select[id^="options-graduation"], select[id^="input-option"], [type="checkbox"][data-toggle="popover_change"], #product input:radio, #product [type="text"]:not(#input-postcode)').change(function () { if($(this).attr('data-product-option-id')){ var data_product_option_id = $(this).attr('data-product-option-id'); $("#preview_graduation" + data_product_option_id + " #img_value").remove(); if ($('#' + $(this).val()).data('image')) { $("#preview_graduation" + data_product_option_id).append("
Item selecionado: "); } } if($('#input-quantity').length > 0){ var product_quantity = $('#input-quantity').val(); } else { var product_quantity = 1; } var total_price_option = 0; var rule_price_type = false; var option_price = 0; var option_points = 0; $('#product select[id^="options-graduation"], #product select[id^="input-option"], #product [data-toggle="popover"].selected, #product [type="checkbox"][data-toggle="popover_change"]:checked, #product [type="text"], #product input:radio:checked').each(function () { if ($('#' + $(this).val()).attr('data-content') || $('#' + $(this).attr('id') + '[type="text"]').attr('data-content') || $(this).hasClass('selected') || $(this).is('checked') || $('.' + $(this).attr('class') + '[type="radio"]').attr('data-content') || $('#' + $(this).val()).attr('data-option-points')) { let att_price = false; if ($('#' + $(this).val()).attr('data-content')) { var price_option = $('#' + $(this).val()).attr('data-content').split("|"); if(price_option[1]) { att_price = true; } } else if($(this).hasClass('selected') && $(this).attr('data-content')){ var price_option = $(this).attr('data-content').split("|"); if(price_option[1]) { att_price = true; } } else if ($('#' + $(this).attr('id') + '[type="text"]').attr('data-content') || $('.' + $(this).attr('class') + '[type="radio"]:checked').attr('data-content')) { var price_option = $(this).attr('data-content').split("|"); if (!$(this).val() == '') { att_price = true; } } if(att_price) { let additional_price = 0; if (price_option[0] == 'sub') { price_option[1] = "-" + price_option[1]; } if ($(this).hasClass('custom-price')) { additional_price = parseFloat($(this).siblings('.option-total').find('.option-total-value').text().replace(',', '.')); } else { additional_price = parseFloat(price_option[1]); } total_price_option += additional_price; if (additional_price && $(this).attr('data-rule-price-type') !== undefined) { rule_price_type = true; } } if($(this).attr('data-option-points')){ option_points = $(this).data('option-points'); } else if($('#' + $(this).val()).attr('data-option-points')){ option_points = $('#' + $(this).val()).data('option-points'); } } }); option_price += total_price_option; $('#simulator_payments_board').hide(); $('.product-single .product-price-attacked:not(.min-attacked)').hide(); $.ajax({ url: 'index.php?route=product/product/priceOption', type: 'post', data: 'product_id=8&option_price=' + option_price + '&product_quantity=' + product_quantity + '&rule_price_type=' + rule_price_type, dataType: 'json', beforeSend: function () { $('#simulator_payments_board').before('
'); }, success: function (json) { $('#simulator_payments_board').show(); $('.product-single .product-price-attacked:not(.min-attacked)').show(); $('.loading').remove(); $('#simulate_payment').html(json.simulate_payment_output); parcel_simulator = json.calculate_prices_output.parcel_simulator; special = json.calculate_prices_output.special; price = json.calculate_prices_output.price; price_simulator = json.calculate_prices_output.price_simulator; price_simulator_no_interest = json.calculate_prices_output.price_simulator_no_interest; price_discount = json.calculate_prices_output.price_discount; special_discount = json.calculate_prices_output.special_discount; special_simulator = json.calculate_prices_output.special_simulator; special_simulator_no_interest = json.calculate_prices_output.special_simulator_no_interest; show_interest_installment = json.calculate_prices_output.show_interest_installment; no_interest_installments = json.calculate_prices_output.no_interest_installments; show_in_cash_discount = json.calculate_prices_output.show_in_cash_discount; text_discount_avista_list_products = json.calculate_prices_output.text_discount_avista_list_products; special_porcent = Math.round(json.calculate_prices_output.special_porcent); text_no_interest = 'sem juros'; if(show_interest_installment && parcel_simulator > no_interest_installments){ text_interest = "com juros"; }else{ text_interest = "sem juros"; } text_discount = ''; if (text_discount_avista_list_products) { text_discount = '
'+ text_discount_avista_list_products +' '; } cash_discount = ''; cash_discount_alert = ''; if (show_in_cash_discount) { cash_discount = '
* Em compras à partir de '+ show_in_cash_discount +' '; cash_discount_alert = '*'; } square = false; var prefix = ""; if (special) { $('.product-single .product-price-old').html('De ' + price); $('.product-single .product-price-new').html('Por ' + special); if(special_discount){ $('.product-single .product-price-discount').html(' ou
'+ special_discount +' à vista ' + text_discount + cash_discount_alert + cash_discount); } $('.product-single .product-price-simulator').html(`
${special} em
${parcel_simulator}x de
${special_simulator} ${text_interest} `); } else { if(!square) { $('.product-single .product-main-price').html(price + prefix); } $('.product-single .product-main-price').html(price); if(price_discount){ $('.product-single .product-price-discount').html(' ou
'+ price_discount +' à vista ' + text_discount + cash_discount_alert + cash_discount); } $('.product-single .product-price-simulator').html(`
${price} em
${parcel_simulator}x de
${price_simulator} ${text_interest} `); } if(json.price_attacked && json.attacked_status){ $('.product-single .product-price-attacked:not(.min-attacked)').html('
Preço de Atacado: ' + json.price_attacked + ' '); } if(option_points){ $('.product-reward-points>strong:first-child').text(option_points); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log(XMLHttpRequest.responseText); } }); }); $('button[id^=\'button-upload\']').on('click', function (event) { var node = $(this); var option_id = node.data('upload-option-id'); $('#form-upload').remove(); $('body').prepend('
'); $('#form-upload input[name=\'file\']').trigger('click'); $('#form-upload').on('change', function(){ if ($('#form-upload input[name=\'file\']').val() != '') { $.ajax({ url: 'index.php?route=tool/upload&upload-option-id=' + node.data('upload-option-id'), type: 'post', dataType: 'json', data: new FormData($('#form-upload')[0]), cache: false, contentType: false, processData: false, beforeSend: function () { $(node).button('loading'); }, success: function (json) { $('.text-danger').remove(); $('.alert-success').remove(); if (json['error']) { $(node).button('reset'); $(node).parent().find('input').after('
' + json['error'] + '
'); } if (json['success']) { swal(json.success); var str = json.filename; var res = str.slice(-4); if(str.length > 30){ var res2 = str.slice(0, 15); } else{ var res2 = str.slice(0, (str.length / 2)); } $(node).html(res2 + '(...)' + res).addClass('btn btn-success').removeClass('disabled').removeAttr('disabled'); $(node).parent().find('input').attr('value', json['code']); } }, error: function (xhr, ajaxOptions, thrownError) { console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); } }); } }); }); $('#button-consult').on('click', function () { $.ajax({ url: 'index.php?route=product/product/price_consult', type: 'post', data: 'product_id=8', dataType: 'json', beforeSend: function () { $('#button-consult').button('loading'); }, complete: function () { $('#button-consult').button('reset'); }, success: function (json) { html = '
'; html += '
'; html += '
'; html += '
'; html += '
' + json.output + '
'; html += '
'; html += '
'; html += '
'; html += '
'; $('.modal-price-consult').remove(); $('body').append(html); $('#modal-price-consult').modal('show'); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.responseText); } }); }); $('.buy-together select').on('change', function(){ $(this).parent().removeClass('has-error'); }); function option_text_require(id){ if(document.getElementById('input-option'+id).value == ''){ document.getElementById('input-option'+id).style.border = '1px solid red'; }else{ document.getElementById('input-option'+id).style.border = '1px solid #ccc'; $('#error-insert').remove(); } } $('.button-cart').on('click', function () { var error_select_option = false; if($(".addBuyTogetherProduct").length){ $(".addBuyTogetherProduct").each(function(index, element) { var product_id = $(this).data("buyTogetherProductId"); if ($(".buy-together-" + product_id + " select").length) { $('.buy-together-' + product_id + " select").each(function (i, e) { if ($(this).val() == 0) { error_select_option = true; $(this).parent().addClass('has-error'); } }); } else { $('.buy-together-' + product_id + " .product_options_list").each(function (i, e) { if ($(this).find('input[type="hidden"]').val() == 0) { error_select_option = true; $(this).parent().addClass('has-error'); } }); } if(error_select_option){ $('#error-insert').remove(); $('.product-single .product-prices-content').after('
Você precisa selecionar algum tamanho!
'); clearTimeout(clear_time); clear_time = setTimeout("$('#error-insert').fadeOut();", 5000); } }); } $('#data-option-text').each(function(index, element){ let required = element.getAttribute('data-required'); let id = element.getAttribute('data-id'); if(id && required == 'true'){ if(document.getElementById('input-option'+id).value == ''){ document.getElementById('input-option'+id).style.border = '1px solid red'; error_select_option = true; $('#error-insert').remove(); $('.product-single .product-prices-content').after('
Preencha o campo obrigatório
'); }else{ $('#error-insert').remove(); } } }); if(!error_select_option){ addCart(); } }); $('.options-list textarea, .options-list input[type="text"]').focusout(function(){ $(this).parent().removeClass('has-error'); $(this).siblings('.alert').remove(); $('.product-option-warning').remove(); }); $('#product input[type="date"]').on('blur', function(){ let date = new Date($(this).val()); date = date.toLocaleDateString('pt-BR'); $(this).next().val(date); }); $('#product input[type="datetime-local"]').on('blur', function(){ let date = new Date($(this).val().split('T')[0]); let time = $(this).val().split('T')[1]; date = date.toLocaleDateString('pt-BR'); $(this).next().val(`${date} ${time}`); }); function addCart(){ var package = ''; var input_data = ''; if($(".sizes").hasClass('packageTrigger selected') || $('.option-type-select').find('.packageTrigger')){ package = 'packageTrigger'; } if($('.buy-together-container').length && !$('.addBuyTogetherProduct').lenght){ input_data = $('#product div:not(.buy-together-content').find('input[type=\'text\'], input[type=\'hidden\']:not(.buy-together-opt), #input-quantity, input[type=\'radio\']:checked, input[type=\'checkbox\']:checked, select:not(.buy-together-opt), textarea').add($('#__csrf')); }else { input_data = $('#product input[type=\'text\'], #product input[type=\'hidden\'], #product #input-quantity, #product input[type=\'radio\']:checked, #product input[type=\'checkbox\']:checked, #product select, #product textarea, #__csrf'); } $.ajax({ url: 'index.php?route=checkout/cart/add&package=' + package, type: 'post', data: input_data, dataType: 'json', beforeSend: function () { $('.button-cart').button('loading'); }, success: function (json) { $('.alert, .text-danger').remove(); $('.form-group').removeClass('has-error'); $('#product .product-option-warning').remove(); if (json['error']) { if (json['error']['option']) { for (i in json['error']['option']) { var element = $('#input-option' + i.replace('_', '-')); if (element.parent().hasClass('input-group')) { element.parent().after('
' + json['error']['option'][i] + '
'); } else { element.after('
' + json['error']['option'][i] + '
'); } } } if (json['error']['recurring']) { $('select[name=\'recurring_id\']').after('
' + json['error']['recurring'] + '
'); } if (json['error']['product']) { $('#button-cart').before('
' + json['error']['product'] + '
'); } if (json['error']['empty_option']) { $('#button-cart').before('
' + json['error']['empty_option'] + '
'); } if($('#product .options-list').length){ $('html, body').animate({scrollTop: $('#product .options-list').offset().top - 60}, 700); } if (json['error']['lojaesquadrao']) { $('#button-cart').before('
' + json['error']['lojaesquadrao'] + '
'); } else { $('
Preencha os campos obrigatórios para prosseguir na compra.
').insertAfter('#product .product-prices-content'); } $('.text-danger').parent().addClass('has-error'); $('.button-cart').button('reset'); } if (json['error_stock']) { $('.button-cart').button('reset'); html = '
'; html += '
'; html += '
'; html += '
'; html += '
' + json['error_stock'] + '
'; html += '
'; html += '
'; html += '
'; html += '
'; $(".top_modal").remove(); $('body').append(html); $('#modal-cart').modal('show'); } if (json.buy_permission) { $.each(json.buy_permission, function(index, value) { if((value == null) && (!json.error && !json.error_stock)){ $('#modal-cart').remove(); $('.modal-content').remove(); swal({ title : 'Produto temporariamente reservado. Ele poderá ficar disponivel caso o cliente venha a desistir do mesmo ', html: '
Qualquer duvida permanecemos a disposição
', type: 'error', timer: 3000, onClose: function() { window.location.href = window.location.href; } }); return false; } else { if(value == 'upon_request'){ swal({ title : 'Produto temporariamente reservado. Você ainda poderá finalizar seu pedido com a nossa exclusiva ferramenta de Sob-Encomenda', html: '
Qualquer duvida permanecemos a disposição
', type: 'error', showConfirmButton: true, timer: 5000, onClose: function() { window.location.href = window.location.href; } }); return false; } } }); } if (!$(".addBuyTogetherProduct").length) { if (json['success_redirect'] && !json['fail_redirect']) { location.href = json['success_redirect']; } if (json.success_modal) { $('#modal-cart').remove(); $('.button-cart').button('reset'); html = '
'; html += '
'; html += '
'; html += '
'; html += json.success_modal; html += '
'; html += '
'; html += '
'; html += '
'; $(".top_modal").remove(); $('body').append(html); $('#modal-cart').modal('show'); $('#cart-total').html(json['total']); $('#cart > ul').load('index.php?route=common/cart/info ul li'); } } else if ($(".addBuyTogetherProduct").length && !json['error'] && !json['error_stock']) { $.each($(".addBuyTogetherProduct"), function(index, val) { var product_id = $(this).data("buyTogetherProductId"); var option = {}; if ($(".buy-together-" + product_id + " select").length) { $(".buy-together-" + product_id + " select").each(function (i, e) { option[$(this).data("product-option-id")] = $(this).val(); }); } else { option[$(".buy-together-" + product_id + " input").data("product-option-id")] = $(".buy-together-" + product_id + " input").val(); } if ($(".buy-together-" + product_id + " input[type='text']").length) { $(".buy-together-" + product_id + " input[type='text']").each(function (i, e) { option[$(this).data("product-option-id")] = $(this).val(); }); } $(this).removeClass('addBuyTogetherProduct'); $.ajax({ url: 'index.php?route=checkout/cart/add', type: 'post', data: { 'product_id' : product_id, 'quantity' : 1, 'option' : option, '__csrf' : $('#__csrf').val() }, dataType: 'json', async: false, beforeSend: function () { $('.button-cart').button('loading'); }, success: function (json) { if (json['error_stock']) { html = '
'; html += '
'; html += '
'; html += '
'; html += '
' + json['error_stock'] + '
'; html += '
'; html += '
'; html += '
'; html += '
'; $(".top_modal").remove(); $('body').append(html); $('#modal-cart').modal('show'); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log(XMLHttpRequest.responseText); } }); }); closeLoad(); location.href = json.success_redirect ?? "/carrinho"; } }, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log(XMLHttpRequest.responseText); } }); } $('#review-form .r_icons input[type="radio"]').on('click', function(){ $('#review-empty').remove(); if ($(this).hasClass('check') ) { $(this).removeAttr('checked'); $(this).removeClass('check'); $('
').insertBefore($('#review-radios1')); } else { $('#review-form .r_icons input[type="radio"]').removeClass('check'); $(this).addClass('check'); $(this).prop('checked', true); $('#review-empty').remove(); } }); $('#button-review').on('click', function () { $('#review-form .modal-body').fadeIn('fast'); $('#review-form .modal-header h2').fadeIn('fast'); $('#review-form .modal-header .text-center.message').remove(); $.ajax({ url: 'index.php?route=product/product/write&product_id=8', type: 'post', dataType: 'json', data: 'name=' + encodeURIComponent($('#review-form input[name=\'name\']').val()) + '&email=' + encodeURIComponent($('#review-form input[name=\'email\']').val()) + '&cellphone=' + encodeURIComponent($('#review-form input[name=\'cellphone\']').val()) + '&text=' + encodeURIComponent($('#review-form textarea[name=\'text\']').val()) + '&rating=' + encodeURIComponent($('#review-form input[name=\'rating\']:checked').val() ? $('#review-form input[name=\'rating\']:checked').val() : '') + '&captcha=' + encodeURIComponent($('#review-form input[name=\'captcha\']').val()), beforeSend: function () { $('#button-review').button('loading'); }, success: function (json) { $('.alert-success, .alert-danger').remove(); $('#button-review').button('reset'); if (json['error']) { $('#review-form').after('
' + json['error'] + '
'); $('#review-form').modal('hide'); } if (json['success']) { $('#review-form').after('
' + json['success'] + '
'); $('#review-form').modal('hide'); $('input[name=\'name\']').val(''); $('input[name=\'email\']').val(''); $('input[name=\'cellphone\']').val(''); $('textarea[name=\'text\']').val(''); $('input[name=\'rating\']:checked').prop('checked', false); $('input[name=\'captcha\']').val(''); $('
').insertBefore($('#review-radios1')); $('#captcha').attr('src', 'index.php?route=tool/captcha#' + new Date().getTime()); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.responseText); } }); }); $('#review-form').on('show.bs.modal', function(){ $('.captcha-image').each(function(){ if (!$(this).hasClass('loaded')) { let captcha_image = ''; captcha_image = captcha_image ? 'data:image/jpeg;base64,' + captcha_image : 'index.php?route=tool/captcha'; $(this).attr('src', captcha_image); $(this).addClass('loaded'); } }); }); $("#review-form").on('show.bs.modal', function(){ $('#review-form .modal-header').html('
Faça uma avaliação × '); $('#review-form .modal-body').fadeIn('fast'); }); $('input[name=\'postcode\']').keydown(function (e) { if (e.keyCode == 13) { $('#button-quote_product').click(); } }); $('.notify-btn').on('click', function () { $('#product_notify').remove(); var product_id = $(this).attr('data-product-id'); var data_product_option_id = $(this).attr('data-product-option-id'); var data_product_option_value_id = $(this).attr('data-product-option-value-id'); if(screen.width >= 992){ $('
').insertBefore('#product'); $('#product').hide(); $('#product_notify').load('index.php?route=product/notify&product_id=' + product_id + '&data_product_option_id=' + data_product_option_id + '&data_product_option_value_id=' + data_product_option_value_id); } else { html = '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; $('body').append(html); $('#notify-content').load('index.php?route=product/notify&product_id=' + product_id + '&data_product_option_id=' + data_product_option_id + '&data_product_option_value_id=' + data_product_option_value_id); $('#modal-notify').modal('show'); } }); $('.product-share-button').click(function(){ $(this).toggleClass('active'); }); if(window.matchMedia("(min-width: 768px)").matches) { $('div.product-options-list .custom-product-stock-image-label').click(function() { if ($(this).prev().hasClass('selected')) { $('.product-image .product-thumbnails li:first-child').click(); } $('div.product-options-list .custom-product-stock-image-label > img').removeClass('current-img'); if($(this).children('.product_stock_image').hasClass('product_stock_image')) { changeStockImage($(this).children('.product_stock_image')); } else { $('.product-image .product-thumbnails li:first-child').click(); } }); } if ($('.options-list .option-type-select').length) { $('.options-list .option-type-select').change(function() { const clickedOptionListElement = $('option[value="' + this.value + '"]'); if (clickedOptionListElement.data('original-image')) { changeStockImage(clickedOptionListElement); } }); } if(window.matchMedia("(max-width: 767px)").matches) { $('div.product-options-list .custom-product-stock-image-label').click(function() { if ($(this).prev().hasClass('selected')) { $('.product-image .product-thumbnails li:first-child').click(); } $('div.product-options-list .custom-product-stock-image-label > img').removeClass('current-img'); if($(this).children('.product_stock_image').hasClass('product_stock_image')) { changeStockImage($(this).children('.product_stock_image')); } else { $('.product-image .product-thumbnails li:first-child').click(); } }); } if(window.matchMedia("(max-width: 767px)").matches) { if($('.product_carousel_mobile').length) { /* QUANDO CARROSSEL TEM MAIS DE UMA IMAGEM */ if($('.product_carousel_mobile.owl-carousel').length) { var old_img_src_caroussel_mobile = $('.product_carousel_mobile .owl-stage > .owl-item.active img').attr('src'); var old_product_carousel_mobile_html = $('#content .product_carousel_mobile').parent().html(); $('ul.product_options_list > li img').click(function() { var product_carousel_mobile_html = $('#content .product_carousel_mobile').parent().html(); loadYoutubeEmbed(); $('ul.product_options_list > li img').removeClass('current-img'); if($(this).hasClass('product_stock_image')) { $('.product_carousel_mobile').parent().html(product_carousel_mobile_html); let img_src = $(this).attr('data-original-image'); $('.product_carousel_mobile .owl-stage > .owl-item.active img').addClass('stock_img_carousel_mobile').attr('src', img_src); $('.popup-zoom .product_carousel_mobile .owl-stage > .owl-item:first-child img').addClass('stock_img_carousel_mobile').attr('src', img_src); } else { if($('.product_carousel_mobile .owl-stage > .owl-item.active img').hasClass('stock_img_carousel_mobile')) { $('.product_carousel_mobile').parent().html(old_product_carousel_mobile_html); } } }); } else { if ($('.custom-product-stock-image-label').length) { $('.product-options-list .custom-product-stock-image-label').click(function() { if($(this).children('.product_stock_image').hasClass('product_stock_image')) { let img_src = $(this).children('.product_stock_image').attr('data-original-image'); $('.product_carousel_mobile .grid_product_picture > img').attr('src', img_src); } }); } else { $('ul.product_options_list > .li_stock_image').click(function() { if($(this).children('.product_stock_image').hasClass('product_stock_image')) { let img_src = $(this).children('.product_stock_image').attr('data-original-image'); $('.product_carousel_mobile .grid_product_picture > img').attr('src', img_src); } }); } } } else { $('ul.product_options_list > .li_stock_image').click(function() { $('ul.product_options_list > li img').removeClass('current-img'); if($(this).children('.product_stock_image').hasClass('product_stock_image')) { changeStockImage($(this).children('.product_stock_image')); } else { $('#carousel li:first-child').click(); } }); } } function dowloadImageProduct (){ let image_popup_height = '1000'; let image_popup_width = '1000'; if(window.matchMedia("(min-width: 768px)").matches) { imageLink = $('.product-preview .product-image-area').attr('src').replace('webp', '').replace(`fit-in/${image_popup_width}x${image_popup_height}/`, ''); $('#btn-download-product-image').attr('href', imageLink); } else{ imageLink = $('.product_carousel_mobile .owl-item.active .item .grid_product_picture img').attr('src').replace('webp', '').replace(`fit-in/${image_popup_width}x${image_popup_height}/`, ''); $('#btn-download-product-image').attr('href', imageLink); } } function changeStockImage(el) { $('.product-preview > img').attr('src', el.attr('data-original-image')); if (el.data('type')) { $('.product-preview > img').attr('data-zoom-image', el.attr('data-zoom-image')); } else { $('.product-preview > img').attr('data-zoom-image', el.attr('data-original-image')); } $('#carousel > li').removeClass('current-img'); el.addClass('image-additional current-img'); if(screen.width > 900){ $('.zoomContainer').remove(); $(".product-preview > img").elevateZoom({backgroundImage: el.attr('data-original-image'), zoomType: "inner", cursor: "crosshair"}); } } function goToReview(){ $(`a[href=#review_content]`).trigger('click'); setTimeout(function() {$('html, body').animate({scrollTop: $('#reviews').offset().top}, 1)}, 100); }