$(document).ready(function(){ f(); updateCart(CART); cookie_agree(); }); var urlCartZipCode = '/cart/'; var cartIcon = ''; if(zipCode != ""){ urlCartZipCode = urlCartZipCode+'?zipCode='+zipCode; } new WOW().init(); var a = [], t = new Set([]); "use strict"; var cartHead = '

MEU CARRINHO

'; c = '

{VARIANT_NAME}

{VARIANT_PRICE}

{VARIANT_QUANTITY_PRESENTATION}

', d = '
Descontos: {CART_DISCOUNT_TOTAL}
', m = '
' + (SHOW_PRODUCT_PRICE ? '
Total {CART_TOTAL}
' : "") + ''+cartIcon+' Ir para o carrinho
'; $("body").on("cart-success", [".flexy-add-to-cart", ".btn-add-to-cart-qty"], function (e, t) { var o = 4e3; var a = $(".cart-sumary .header-mini-cart"); updateCart(t); if($(window).width()>991){ a.addClass("open"); window.setTimeout(function () { a.removeClass("open"); }, o) } else { window.location.href = '/cart'; /*alert("Produto adicionado ao carrinho!");*/ } }), $("body").on("cart-error", function (e, t) { alert(t); }); $("body").find(".holder").length || $("body").append("
"); $("div.holder").jPages({ containerID: "products", previous: ".feature-block a[data-role='prev']", next: ".feature-block a[data-role='next']", animation: "fadeInRight", perPage: 4 }); function updateCart(e) { var t = SHOW_PRODUCT_PRICE ? $.number(e.totalWithDiscount, 2, ",", ".") : "", o = $(".shopping-cart-content").empty(), a = (function (e) { var t = []; if ((0 < e.items.length && (t = $.merge(t, e.items)), e.sales && 0 < e.sales.length)) for (var o = 0; o < e.sales.length; o++) t = $.merge(t, e.sales[o].items); return t; })(e); o.append(cartHead); if (e && 0 != a.length) { for (var i = 0, s = 0; s < a.length; s++) { var n = a[s], r = SHOW_PRODUCT_PRICE ? "R$ " + $.number(n.totalPriceWithDiscount, 2, ",", ".") : "", l = n.quantity; n.variant.isFractionalStock && (l = 1), o.append( c .replace("{PRODUCT_IMAGE}", n.image ? n.image : "/bundles/flexyftwostore/img/product-placeholder.gif") .replace("{VARIANT_NAME}", n.name) .replace("{VARIANT_PRICE}", r) .replace("{VARIANT_QUANTITY_PRESENTATION}", g(n.quantity) + "x") ), (i += l); } o.append(m.replace("{CART_TOTAL}", "R$ " + t)); 0 < e.salePromotionDiscountTotal && SHOW_PRODUCT_PRICE && o.append(d.replace("{CART_DISCOUNT_TOTAL}", "R$ " + $.number(e.salePromotionDiscountTotal, 2, ",", "."))), $(".cart-items-count").html(Number(i)); } else o.html(cartHead+"

Nenhum produto em seu carrinho.

"); } function g(e) { return -1 < (e = e.toString()).indexOf(".") && (e = (e = Number(e).toFixed(3)).replace(".", ",")), e; } function f() { if ($("[name='customer[type]']").length) { var e = $("[name='customer[type]']").val(), t = $("#customer_customerType"), o = t.find("option"); "cpf" == e ? ($(".cpf").show().find(":input").attr("required", "required"), $(".cnpj").hide().find(":input").removeAttr("required"), t.val( o.filter(function () {return "B2C" == $(this).text();}).val() )) : ($(".cnpj").show().find(":input:not(#check):not(#customer_taxationRegime)").attr("required", "required"), $(".cpf").hide().find(":input").removeAttr("required"), t.val( o.filter(function () { return "B2B" == $(this).text();}).val() )); } } function h(e) { return (e = e.replace(/\./g, "")), parseFloat(e.replace(/,/g, ".")); } function s1(e, t) { return !(t && t < e) || (alert("Não foi possível adicionar " + e + " produtos ao carrinho."), !1); // + " Atualmente possuímos apenas " + t } //general $(".time").countdown({ date: new Date(new Date().getTime() + 864e5), yearsAndMonths: !0, leadingZero: !0 }); $(".ul-side-category li a").click(function () { var e = $(this).next(); return !e.hasClass("sub-category") || ("none" === e.css("display") ? $(this).next().slideDown() : ($(this).next().slideUp(), $(this).next().find(".sub-category").slideUp()), !1); }); $("[name='customer[type]']").on("change blur", function () { f(); }); $("#check").on("change click", function () { $(this).is(":checked") ? $("#customer_cnpj_stateRegistration").addClass("readonly").attr("readonly", "readonly").val("ISENTO") : $("#customer_cnpj_stateRegistration").removeClass("readonly").removeAttr("readonly").val(""); }); $(".main-category-block label").on("click", function () { window.location.href = $(this).data("url"); }); $("#partners img").on("mouseenter", function (e) { var t = $(this); t.data("src", t.attr("src")).attr("src", t.data("hover")); }).on("mouseleave", function (e) { var t = $(this); t.attr("src", t.data("src")); }); $(".flexy-cart-product-quantity, .input-number-inf") .on("focus", function (e) { var t = $(this); t.data("quantity", h(t.val())); }) .on("blur", function (e) { var t = $(this); t.val() && t.val() != t.data("quantity") ? t.trigger("change") : t.val(t.data("quantity")); }); $(".tool_tip").tooltip(); $("#product-zoom").elevateZoom({ zoomType: "inner", cursor: "crosshair", zoomWindowFadeIn: 500, zoomWindowFadeOut: 750 }); $(".stock-verified").on("change keypress keyup keydown", function (e) { var t = $(this); s1(Number(t.val()), t.data("stock")) || (t.val(g(t.data("stock"))).trigger("change"), e.preventDefault(), e.stopImmediatePropagation()); }); var w, b = $(".flexy-weight-mask"); b.mask("#######0,000", { placeholder: "0,000", reverse: !0 }); b.on("keyup", function (i) { clearTimeout(w), (w = setTimeout(function () { var e, t, o, a; (e = i), (t = $(this).val()), (o = $(this)), (a = o.data("stock")), (s(h(t), a) || (o.val(g(a)).trigger("change"), e.preventDefault(), e.stopImmediatePropagation(), 0)) && $(this).trigger("blur"); }, 1200)); }), b.on("keydown", function (e) { clearTimeout(w); }) //home var s = 0, o = $("#header"), a = $("#header-main-fixed"), n = $(".header-bg"); $(window).scroll(function () { if($(window).width() > 990){ var e = $(this).scrollTop(); s < e ? 41 < e && (o.addClass("header-top-fixed"), n.addClass("header-bg-fixed"), a.addClass("header-main-fixed")) : e < 100 && (o.removeClass("header-top-fixed"), a.removeClass("header-main-fixed"), n.removeClass("header-bg-fixed")), (s = e); } }); $(".dropdown").hover( function () { $(this).addClass("open"); }, function () { $(this).removeClass("open"); } ); $('#selectCustomer').select2({ placeholder: ' - selecione um cliente -', }).change(function (e) { e.preventDefault(); var selectedData = $(this).val(); }); $("#selectCustomer").change(function() { var customerId = $(this).val(); if (customerId == "new") { window.location.href = urlCustomerCreate; return; } $.ajax({ url : urlCustomerChange, data : { customerId : customerId }, success : function() { window.location.reload(); }, error : function() { alert("{{ 'store.customerSelectError'|trans }}"); } }); }); $("#nav-tabs .next").click(function () { $("#owl-new").trigger("owl.next"), $("#owl-featured").trigger("owl.next"); }), $("#nav-tabs .prev").click(function () { $("#owl-new").trigger("owl.prev"), $("#owl-featured").trigger("owl.prev"); }), $("#nav-tabs2 .next").click(function () { $("#owl-new2").trigger("owl.next"), $("#owl-featured2").trigger("owl.next"); }), $("#nav-tabs2 .prev").click(function () { $("#owl-new2").trigger("owl.prev"), $("#owl-featured2").trigger("owl.prev"); }), $('.home-product-carousel').owlCarousel({ items: 3, itemsCustom: !1, itemsDesktop: [1199, 3], itemsDesktopSmall: [980, 3], itemsTablet: [768, 1], itemsTabletSmall: !1, itemsMobile: [650, 1], singleItem: !1, itemsScaleUp: !1, responsive: !0, responsiveRefreshRate: 200, responsiveBaseWidth: window, autoPlay: !1, stopOnHover: !1, navigation: true, pagination: true, }); $('.product-related-carousel').owlCarousel({ items: 3, itemsCustom: !1, itemsDesktop: [1199, 3], itemsDesktopSmall: [980, 3], itemsTablet: [768, 1], itemsTabletSmall: !1, itemsMobile: [650, 1], singleItem: !1, itemsScaleUp: !1, responsive: !0, responsiveRefreshRate: 200, responsiveBaseWidth: window, autoPlay: !1, stopOnHover: !1, navigation: true, pagination: true, }); //navigation function filterToggle(){ $(".sidebar-menu").animate({ opacity: "toggle" }, 500, function() { // Animation complete. }); $(".filter-menu-modal-close").animate({ opacity: "toggle" }, 500, function() { // Animation complete. }); } $( ".filter-menu-btn" ).click(function() { $("html").addClass("mobile-html-fix"); $("body").addClass("mobile-body-fix"); $(".top-page").css("display", "block"); filterToggle(); }); $( ".filter-menu-modal-close" ).click(function() { $("html").removeClass("mobile-html-fix"); $("body").removeClass("mobile-body-fix"); $(".top-page").css("display", "none"); filterToggle(); }); $('.flexy-list-btn').click(function(event){ event.preventDefault(); $('.flexy-display-mode').addClass('flexy-list-display'); }); $('.flexy-grid-btn').click(function(event){ event.preventDefault(); $('.flexy-display-mode').removeClass('flexy-list-display'); }); //cart and freight $(".additional-add-to-cart").on("click", function () { var e, t, o = $(this).data("variant-id"); -1 < i(o) ? ((t = o), a.splice(i(t), 1), alert("Produto removido!")) : ((e = o), a.push(e), alert("Produto adicionado!")), $(".main_cart_add").data("additional-variant-ids", a); }); $(".coupon-validate").on("keyup", function (e) { $(this).val( $(this) .val() .replace(/[^0-9a-zA-Z_]/g, "") ); }); $("body").on("click", ".btn-cep", function(event){ if (-1 !== window.location.pathname.indexOf("quote")) { var e = $(".flexy-input-postcode").val(), t = [location.protocol, "//", location.host, location.pathname].join("") + "?zipCode=" + e, o = ""; $(".f2-quote-observation").each(function () { var e = $(this).data("observation"), t = $(this).val(); o += "&" + e + "=" + t; }), (window.location = t + o); } }); $("body").on("click", ".additional-to-cart", function(event) { var e = $(this).data("addition-id"); t.add(e), $(".flexy-add-to-cart").one("cart-error", function () { t.delete(e); }); }); $("body").on("click", ".btn-add-to-cart-qty", function(event) { var $this = $(this); var inputQty = $this.parents('.controls-add-cart').find('.product-quantity'); var qty = parseFloat($(inputQty).val()); var id = $this.data('variant-id'); var additionalIds = $this.data('additional-variant-ids') || []; var dc = $this.data('distributioncenter') || []; var varId = $this.data('variant-id'); $.ajax({ url: '/cart/add', type: 'post', dataType: 'json', data: { id: varId, quantity: qty, additionalVariantId: additionalIds, distributionCenter: dc }, beforeSend: function () { $this.parents('.controls-add-cart').find('.btn-add-to-cart-qty').attr("disabled", !0); }, success: function (data) { $this.parents('.controls-add-cart').find('.btn-add-to-cart-qty').trigger("cart-success", [data.cart]); //location.href = '/cart/'; }, error: function (data) { alert(data.responseJSON.error); $(inputQty).val(qty); } }) .always(function () { $this.parents('.controls-add-cart').find('.btn-add-to-cart-qty').removeAttr("disabled"); }) }); jQuery(function($){ $("body").on("click", ".card_product_quantity button.remove", function(event) { let inputQty = $( this ).parents('.card_product_quantity').find('.product-quantity'); let qty = parseFloat($(inputQty).val()); if (qty > 1) { $(inputQty).val(qty - 1); } $(inputQty).blur(); }); $("body").on("click", ".card_product_quantity button.add", function(event) { let inputQty = $( this ).parents('.card_product_quantity').find('.product-quantity'); let qty = parseFloat($(inputQty).val()); $(inputQty).val(qty + 1); $(inputQty).blur(); }); }); function resetPaymentFlags(){ $('.nav-credit-flags').find("li").each(function() { var imgLi = $(this).find('img'); $(imgLi).css('opacity', '1'); }) } $(".nav-credit-flags").on("click", function (){ $('.nav-credit-flags').find("li").each(function() { var radioLi = $(this).find('input[type=radio]'); var imgLi = $(this).find('img'); if($(radioLi).is(":checked")) { $(imgLi).css('opacity', '1'); } else { $(imgLi).css('opacity', '0.1'); } }) $('.credit-card-fields').show(); }); $('#payment-box').click(function(e) { if($(".payment-box").hasClass("disabled")){ alert("Selecione um endereço e uma forma de entrega!"); } }); $("#customer_defaultShippingAddress_postcode").blur(function(e){ var cep = $(this).val(); $.ajax({ type: 'GET', url: "https://viacep.com.br/ws/"+cep+"/json/", dataType: "JSON", success: (resp) =>{ $("#customer_defaultShippingAddress_city").val(resp.localidade); $("#customer_defaultShippingAddress_state").val(resp.uf); $("#customer_defaultShippingAddress_district").val(resp.bairro); $("#customer_defaultShippingAddress_street").val(resp.logradouro); }, error: (resp) =>{ console.log(resp); } }); }); $("#address_postcode").blur(function(e){ var cep = $(this).val(); $.ajax({ type: 'GET', url: "https://viacep.com.br/ws/"+cep+"/json/", dataType: "JSON", success: (resp) =>{ $("#address_city").val(resp.localidade); $("#address_state").val(resp.uf); $("#address_district").val(resp.bairro); $("#address_street").val(resp.logradouro); }, error: (resp) =>{ console.log(resp); } }); }); function cookie_agree(){ var cook = Cookies.get('agree_cookies'); $('.cookie_test').html(cook); if (cook != "accept"){ $('.lgpd').show(); } } $(".block-accordion .title").on("click", function (e){ var block = $(this).parents('.block-accordion').find('.info-block'); if($(block).is(":visible")){ $(block).hide(); } else{ $('.info-block').hide(); $(block).show(); } }); $('.menu-btn-close').click(function() { $(".navbar-toggle").trigger("click"); }); $(".title-box").on("click", function (e){ if($( window ).width() < 991){ var ul = $(this).parents('.box-links').find('ul'); if($(ul).is(":visible")){ $(ul).hide(); } else{ $(ul).show(); } } }); $(".select-box span.arrow").on("click", function (e){ var element = document.getElementById('list-order'); var event; event = document.createEvent('MouseEvents'); event.initMouseEvent('mousedown', true, true, window); element.dispatchEvent(event); }); function shippingCalculation() { var postcode = $('.f2-shipping-estimate-postcode').val(); var container = $('.f2-shipping-estimate-container'); var variantId = $('.f2-shipping-estimate-variant-id').val(); if (variantId == undefined) { alert('Informe o produto'); return; } if (postcode == undefined || postcode === "") { alert('Informe o CEP'); return; } $("input[name='distributionCenterReferenceCode']").each(function() { var dcRefCode = $(this).val(); $('#shipping-'+dcRefCode).show(); $.calculate_shipping_by_variant( 'html', function (data) { $('#shipping-'+dcRefCode).html('
Calculando frete...
'); }, function (data) { $('#shipping-'+dcRefCode).html(data); container.html(''); }, postcode, $('.f2-shipping-estimate-quantity').val(), variantId, dcRefCode ); }); } function shippingCalculationOnLoad(){ if(zipCode != "" && calculateBoyBox){ shippingCalculation2(); } } function shippingCalculation2() { var postcode = $('.f2-shipping-estimate-postcode').val(); var container = $('.f2-shipping-estimate-container'); var variantId = $('.f2-shipping-estimate-variant-id').val(); if (variantId == undefined) { alert('Informe o produto'); return; } if (postcode == undefined || postcode === "") { alert('Informe o CEP'); return; } var dcQuantity = $("input[name='distributionCenterReferenceCode']").size(); var cntAux = 0; $('.buy-box-load').css('display', 'flex'); $("input[name='distributionCenterReferenceCode']").each(function() { var dcRefCode = $(this).val(); $('#shipping-'+dcRefCode).show(); $.calculate_shipping_by_variant( 'json', function (data) { $('.buy-best-price-'+dcRefCode).html(''); }, function (data) { var dataReturn = JSON.parse(JSON.stringify(data)); var dataVar = []; console.log('Loja: '+dcRefCode); for(var i in dataReturn) { dataVar.push(dataReturn[i]); console.log(dataReturn[i].name+': de '+dataReturn[i].deliveryTimeFrom +' até '+dataReturn[i].deliveryTimeTo); } dataVar.sort(sortShippingArray()); var timeShipping = dataVar[0].deliveryTimeTo; var messageShip = "Entrega indisponível"; if(timeShipping != undefined){ messageShip = "até "+timeShipping+" dia(s)"; if (timeShipping == 0){ messageShip = "hoje!"; } if (dataVar[0].name == "shipping.method.pickuponplace"){ messageShip = "Retira em Loja - " +messageShip; } $('#shipping-'+dcRefCode).parents('.buy-box-content').find('.btn-comprar').removeAttr("disabled"); } else{ $('#shipping-'+dcRefCode).parents('.buy-box-content').find('.btn-comprar').attr("disabled", !0); } $('#shipping-'+dcRefCode).html(messageShip); $('#buy-box-content-'+dcRefCode).attr('data-min-shipping', timeShipping); container.html(''); cntAux++; if(cntAux === dcQuantity){ orderBuyBox(0); $('.buy-box-load').hide(); //shippingCalculation(); } }, postcode, $('.f2-shipping-estimate-quantity').val(), variantId, dcRefCode ); }); } var actualOrientation = 0; $("body").on("click", ".best-price-order", function(event) { if(actualOrientation === 0){ orderBuyBox(1); } else { orderBuyBox(0); } }); function sortShippingArray(){ return function(a, b) { return Number.parseFloat(a.deliveryTimeTo) < Number.parseFloat(b.deliveryTimeTo) ? -1 : Number.parseFloat(a.deliveryTimeTo) > Number.parseFloat(b.deliveryTimeTo) ? 1 : 0; } } function orderBuyBox(orientation){ var $wrapper = $('.buy-box-block'); $wrapper.find('.buy-box-content').sort(function (a, b) { if ($(a).hasClass('disabled')){ console.log('a is disabled'); return 1; } else if ($(b).hasClass('disabled')){ console.log('b is disabled'); return -1; } else if (orientation === 0) { if(Number.parseFloat(a.dataset.minShipping) < Number.parseFloat(b.dataset.minShipping)){ return -1; } if(Number.parseFloat(a.dataset.minShipping) > Number.parseFloat(b.dataset.minShipping)){ return 1; } if(Number.parseFloat(a.dataset.minShipping) == Number.parseFloat(b.dataset.minShipping)){ if(Number.parseFloat(a.dataset.bestValue) < Number.parseFloat(b.dataset.bestValue)){ return 1; } if(Number.parseFloat(a.dataset.bestValue) > Number.parseFloat(b.dataset.bestValue)){ return -1; } } return 0; } else{ alert('Erro ao ordenar buybox'); } }) .appendTo( $wrapper ); actualOrientation = orientation; } $('#zipCode').keyup(function(e){ if(e.keyCode == 13) { shippingCalculation2(); } }); $('.f2-shipping-estimate-quantity').on('input',function(e){ var maxinput = $(this).attr('max'); if(maxinput > 0) { if(parseInt($(this).val()) > parseInt(maxinput)) { alert('Estoque máximo de: '+maxinput); $(this).val(maxinput); } } }); $('.f2-multiple-dc-shipping-estimate-action-2').on('click', function (e) { e.preventDefault(); grava_cookie('zipCode', $('.f2-shipping-estimate-postcode').val()); shippingCalculation2() }); function grava_cookie(key, value){ Cookies.set(key, value, { expires: 365 }); } function get_cookie(key){ return Cookies.get(key); } $("footer .title").on("click", function (e){ var ul = $(this).parents('.menus').find('ul'); if($(ul).is(":visible")){ $(ul).hide(); } else{ $('.menus ul').hide(); $(ul).show(); } }); $(".search-box-target").on("click", function (e){ e.preventDefault(); var searchBox = $(this).parents('.search-item').find('.search-box'); if($(searchBox).is(":visible")){ $(searchBox).hide(); } else{ $('.search-box').hide(); $(searchBox).show(); } }); $("button.account-toggle").on("click", function (e){ var cd = $('.account-area .customer-data'); if($(cd).is(":visible")){ $(cd).hide(); } else{ $(cd).show(); } }); var optionsRating = { max_value: 5, step_size: 1, initial_value: 0, cursor: 'default', readonly: false, change_once: false } $('.flexy-product-review-rating-stars').rate(optionsRating); $('.flexy-product-review-rating-stars').on("click", function (e){ $('.flexy-product-review-rating[type=hidden]').val($('.flexy-product-review-rating-stars').attr("data-rate-value")); }); var policeAgree = false; $(".client-police-agreement").on("click", function (e){ if($(this).val() == "not"){ $(this).val("yes"); policeAgree = true; } else{ $(this).val("not"); policeAgree = false; } }); $(".form-client-validator").on("submit", function (e){ if(!policeAgree){ e.preventDefault(); alert("É preciso ler e concordar com as políticas da Blindex®"); } }); $(".input-zip a").on("click", function (e){ e.preventDefault(); if(validateZipFancy()){ location.reload(); } else{ $('.city-fancy').html('CEP inválido!'); } }); function validateZipFancy(){ var inZipCode = $('.input-zip .cep').val(); return inZipCode.length == 9; } function getCity(){ var cep = $('.input-zip .cep').val().replace('-', ''); $.ajax({ type: 'GET', url: "https://viacep.com.br/ws/"+cep+"/json/", dataType: "JSON", beforeSend: () =>{ $('.city-fancy').html(''); }, success: (resp) =>{ if(resp.erro){ $('.city-fancy').html('Cidade não encontrada'); } else{ $('.city-fancy').html(''+resp.localidade); grava_cookie('zipCode', cep); } }, error: (resp) =>{ $('.city-fancy').html('Cidade não encontrada'); console.log('error: '+resp); } }); } $(".input-zip .cep").on("keyup", function (e) { if(validateZipFancy()){ getCity(); } }); $(".no-cep-btn").on("click", function (e) { var cep = "null" grava_cookie('zipCode', cep); location.reload(); }); $(".opcoes ul li a img").hover(function(){ var pop_type = $(this).parents('li').find(".pop-type"); pop_type.show(); }); $(".opcoes ul li a img").mouseout(function(){ var pop_type = $(this).parents('li').find(".pop-type"); pop_type.hide(); }); $('#submit-assunto').on("click", function (e){ let select_val = document.getElementById("select-assunto").value document.getElementById("subject").value = select_val });