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

Resumo do 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 { 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}", "Qtd: " + g(n.quantity)) ), (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, ",", "."))), window.innerWidth < 991 || screen.width < 991 ? $(".cart-items-count").html('' + Number(i) + "") : $(".cart-items-count").html(Number(i)); } else o.html("

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 s(e, t) { return !(t && t < e) || (alert("Não foi possível adicionar " + e + " produtos ao carrinho."), !1); // + " Atualmente possuímos apenas " + t } // search controls function e() { $(".search-box").animate({ opacity: "toggle" }, 500, function () {}), $(".search-modal-background").animate({ opacity: "toggle" }, 500, function () {}); } $(".search-box-toggle").click(function () { e(), $(".search-input").focus(); }); $(".search-modal-background").click(function () { e(); }); //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); s(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 t = 0, o = $("#header"), a = $("#header-main-fixed"), n = $(".header-bg"), r = $(".top-header-bg"), l = document.getElementById("gotop"), u = null != l; $(window).scroll(function () { var e = $(this).scrollTop(); t < e ? 50 < e && (o.addClass("header-top-fixed"), o.find(".header-top-row").addClass("dis-n"), n.addClass("header-bg-fixed"), a.addClass("header-main-fixed"), r.addClass("top-header-bg-fix"), u && (l.style.display = "block")) : e < 50 && (o.removeClass("header-top-fixed"), o.find(".header-top-row").removeClass("dis-n"), a.removeClass("header-main-fixed"), n.removeClass("header-bg-fixed"), r.removeClass("top-header-bg-fix"), u && (l.style.display = "none")), (t = 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 }}"); } }); }); $(".product-related-nav .next").click(function () { $($(this).data("carousel")).trigger("owl.next"); }); $(".product-related-nav .prev").click(function () { $($(this).data("carousel")).trigger("owl.prev"); }); $(".top-page").click(function () { (document.body.scrollTop = 0), (document.documentElement.scrollTop = 0); }), $("#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: 4, itemsCustom: !1, itemsDesktop: [1199, 4], itemsDesktopSmall: [980, 3], itemsTablet: [768, 2], itemsTabletSmall: !1, itemsMobile: [650, 2], singleItem: !1, itemsScaleUp: !1, responsive: !0, responsiveRefreshRate: 200, responsiveBaseWidth: window, autoPlay: !1, stopOnHover: !1, navigation: true, }); $('.home-product-carousel-seller').owlCarousel({ items: 3, itemsCustom: !1, itemsDesktop: [1199, 3], itemsDesktopSmall: [980, 2], itemsTablet: [768, 2], itemsTabletSmall: !1, itemsMobile: [650, 2], singleItem: !1, itemsScaleUp: !1, responsive: !0, responsiveRefreshRate: 200, responsiveBaseWidth: window, autoPlay: !1, stopOnHover: !1, navigation: true, }); $('.product-related-carousel').owlCarousel({ items: 4, itemsCustom: !1, itemsDesktop: [1199, 4], itemsDesktopSmall: [980, 3], itemsTablet: [768, 2], itemsTabletSmall: !1, itemsMobile: [650, 2], singleItem: !1, itemsScaleUp: !1, responsive: !0, responsiveRefreshRate: 200, responsiveBaseWidth: window, autoPlay: !1, stopOnHover: !1, navigation: true, }); /* $('#gal1').owlCarousel({ items: 1, itemsCustom: !1, itemsDesktop: [1199, 4], itemsDesktopSmall: [980, 4], itemsTablet: [630, 4], itemsTabletSmall: !1, itemsMobile: [479, 4], singleItem: !1, itemsScaleUp: !1, responsive: !0, responsiveRefreshRate: 200, responsiveBaseWidth: window, autoPlay: !1, stopOnHover: !1, navigation: !1, }); */ //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(); }); /* $(window).resize(function() { if($(window).width() > 992){ $(".sidebar-menu").css("display", "block"); $(".filter-menu-modal-close").css("display", "none"); }else{ $(".sidebar-menu").css("display", "none"); $(".filter-menu-modal-close").css("display", "none"); } }); */ $('.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'); }); //product var e = $("#gal1"); e.find("a[data-image]").hover(function () { $(".product-media-details").removeClass("video"); var e = $(this).attr("data-image"), t = $(this).attr("data-zoom-image"); $("#product-zoom").data("elevateZoom").swaptheimage(e, t); }), e.find("a[data-video]").on("mouseover", function () { var e = $(this), t = $(".product-media-details"), o = t.find(".product-video"); o.find("iframe").remove(), o.append('
'); new YT.Player("player", { width: "100%", videoId: e.data("video"), events: { onReady: function (e) { e.target.playVideo(); }, }, }); t.addClass("video"); }); //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-qty button.remove", function(event) { let inputQty = $( this ).parents('.btn-qty').find('.product-quantity'); let embalagem = inputQty.data('embalagem'); let qty = parseFloat($(inputQty).val()); if (qty > embalagem) { $(inputQty).val(qty - embalagem); } else{ $(inputQty).val(embalagem); } }); $("body").on("click", ".btn-qty button.add", function(event) { let inputQty = $( this ).parents('.btn-qty').find('.product-quantity'); let embalagem = inputQty.data('embalagem'); let qty = parseFloat($(inputQty).val()); $(inputQty).val(qty + embalagem); }); $("body").on("click", ".card_product_quantity button.remove", function(event) { $(this).prop("disabled",true); let inputQty = $( this ).parents('.card_product_quantity').find('.flexy-cart-product-quantity'); let embalagem = inputQty.data('embalagem'); let qty = parseFloat($(inputQty).val()); if (qty > embalagem) { $(inputQty).val(qty - embalagem); } else{ $(inputQty).val(embalagem); } $('.flexy-cart-product-quantity').blur(); }); $("body").on("click", ".card_product_quantity button.add", function(event) { $(this).prop("disabled",true); let inputQty = $( this ).parents('.card_product_quantity').find('.flexy-cart-product-quantity'); let embalagem = inputQty.data('embalagem'); let qty = parseFloat($(inputQty).val()); $(inputQty).val(qty + embalagem); $('.flexy-cart-product-quantity').blur(); }); $("body").on("click", ".shopping-cart-buttons button.remove", function(event) { let inputQty = $( this ).parents('.shopping-cart-buttons').find('.product-quantity'); let embalagem = inputQty.data('embalagem'); let qty = parseFloat($(inputQty).val()); if (qty > embalagem) { $(inputQty).val(qty - embalagem); } else{ $(inputQty).val(embalagem); } }); $("body").on("click", ".shopping-cart-buttons button.add", function(event) { let inputQty = $( this ).parents('.shopping-cart-buttons').find('.product-quantity'); let embalagem = inputQty.data('embalagem'); let qty = parseFloat($(inputQty).val()); $(inputQty).val(qty + embalagem); }); $("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"); }) }); function grava_cookie(){ Cookies.set('cookie_prod_info', 'accept', { expires: 365 }); } function cookie_produto(){ var cook = Cookies.get('cookie_prod_info'); if (cook != "accept"){ $("#dialog").fancybox({ 'afterClose' : function() { grava_cookie(); } }).trigger('click'); } } $(".nav-credit-flags").on("click", function (e){ if ($(".shipping-method").length == 0 || !isAllShippingMethodSelected()) { e.preventDefault(); e.stopImmediatePropagation(); alert("Selecione um endereço e uma forma de entrega."); return false; } $('.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>.form-group').show(); }); function isAllShippingMethodSelected(){ var values = {}; $(".shipping-method").each(function(){ var $this = $(this); var isChecked = false; if((isChecked = $this.is(':checked')) || $.inArray($this.attr('name'), Object.keys(values)) < 0) { values[$this.attr('name')] = isChecked; } }); for(var name in values) { if (!values[name]) { return false; } } return true; } $(".title-box").on("click", function (e){ var ul = $(this).parents('.box-links').find('ul'); if($(ul).is(":visible")){ $(ul).hide(); } else{ $(ul).show(); } }); $('.menu-btn-close').click(function() { $(".navbar-toggle").trigger("click"); }); $('.product-quantity').focus(function(){ $('.btn-add-to-cart-qty').prop("disabled",true); }) $('.product-quantity').change(function(e){ validateQuantityChange($(this)); }); $('.flexy-cart-product-quantity').change(function(e){ validateQuantityChange($(this)); }); function validateQuantityChange(qtyIn){ var embalagem = qtyIn.data('embalagem'); var qtyInput = qtyIn.val().replace(',','.'); var variante = (qtyInput/embalagem); var newInput = Math.ceil(variante)*embalagem; if(newInput == 0){ newInput = embalagem }; qtyIn.val(newInput); $('.btn-add-to-cart-qty').prop("disabled",false); } $(".state").on("mouseover", function () { $(this).find('.label_state').show(); }); $(".state").on("mouseout", function () { $(this).find('.label_state').hide(); }); $(".state").on("click", function (e) { var state = $(this); var labelUf = $(state).find('.label_icon_state'); $('.label_icon_state').removeClass('active'); $(labelUf).addClass('active'); e.preventDefault(); $('.representante').each(function(){ var uf = String($(this).find('.nome').text()); var uf = uf.split(" - "); var uf = uf[uf.length - 1]; var ufC = $(labelUf).text(); console.log(uf); console.log(ufC); if(uf == ufC){ $(this).show(); } else{ $(this).hide(); } }); });