(function($, CART) { var player; $(function() { "use strict"; var itemHtmlTemplate = ( '
' + '
' + '
' + '' + '
' + '
' + '

{VARIANT_NAME}

' + '
' + '
' + '' + '{VARIANT_PRICE}
' + '{VARIANT_QUANTITY_PRESENTATION}' + '
' + '
' + '
' + '
' ); var discountsHtmlTemplate = ( '
' + '
' + 'Descontos: {CART_DISCOUNT_TOTAL}' + '
' + '
' ); var totalHtmlTemplate = ( '
' + '
' + (SHOW_PRODUCT_PRICE ? 'Total: {CART_TOTAL}' : '') + '

' + '   Ir para o carrinho' + '
' + '
' ); var emptyCartTemplate = '

Nenhum produto em seu carrinho.

'; /** * * @param timeout */ function showCartSummaryTemp(timeout) { var $header; $header = $(".cart-sumary .header-mini-cart"); $header.addClass("open"); window.setTimeout(function() { $header.removeClass("open"); }, timeout); } /** * * @param cart * @returns {Array} */ function unnestleCartItems(cart) { var items = []; if (cart.items.length > 0) { items = $.merge(items, cart.items); } if (cart.sales && cart.sales.length > 0) { for (var i=0; i'); await updateCartInformation(cart); renderCartSummary(cart); } function addQuantityItemToCart(cart) { const items = unnestleCartItems(cart); var totalItems = 0; for (var i=0; i < items.length; i++) { var item = items[i]; var itemQuantity = item.quantity; if(item.variant.isFractionalStock) { itemQuantity = 1; } totalItems = totalItems + itemQuantity; } if(window.innerWidth < 991 || screen.width < 991) { $(".cart-items-count").html('' + Number(totalItems) + ''); } else { $(".cart-items-count").html(Number(totalItems) + ' ' + (Number(totalItems) > 1 ? 'itens' : 'item')); } } /** * * @param cart */ function renderCartSummary(cart) { var pricePlaceHolder = ''; var totalPrice = SHOW_PRODUCT_PRICE ? $.number(cart.totalWithDiscount, 2, ',', '.') : pricePlaceHolder; var $dropdownCart = $(".shopping-cart-content").empty(), items = unnestleCartItems(cart); if (!cart || items.length == 0) { $dropdownCart.html(emptyCartTemplate); return; } var totalItems = 0; for (var i=0; i < items.length; i++) { var item = items[i]; var itemPrice = SHOW_PRODUCT_PRICE ? ('R$ ' + $.number(item.totalPriceWithDiscount, 2, ',', '.')) : pricePlaceHolder; var itemQuantity = item.quantity; if(item.variant.isFractionalStock) { itemQuantity = 1; } $dropdownCart.append( itemHtmlTemplate .replace('{PRODUCT_IMAGE}', item.image ? item.image : '/bundles/flexyftwostore/img/product-placeholder.gif') .replace('{VARIANT_NAME}', item.name) .replace('{VARIANT_PRICE}', itemPrice) .replace('{VARIANT_QUANTITY_PRESENTATION}', 'Qtd: '+mask3decimals(item.quantity)) ); totalItems = totalItems + itemQuantity; } if (cart.salePromotionDiscountTotal > 0 && SHOW_PRODUCT_PRICE) { $dropdownCart.append( discountsHtmlTemplate.replace('{CART_DISCOUNT_TOTAL}', 'R$ ' + $.number(cart.salePromotionDiscountTotal, 2, ',', '.')) ); } if(window.innerWidth < 991 || screen.width < 991) { $(".cart-items-count").html('' + Number(totalItems) + ''); } else { $(".cart-items-count").html(Number(totalItems) + ' ' + (Number(totalItems) > 1 ? 'itens' : 'item')); } $dropdownCart.append(totalHtmlTemplate.replace('{CART_TOTAL}', 'R$ ' + totalPrice)); } /** * * @param quantity * @param limit */ function verifyStockLimit(quantity, limit) { if (limit && quantity > limit) { alert("Não foi possível adicionar " + quantity + " produtos ao carrinho. Atualmente possuímos apenas " + limit); return false; } return true; } //Keep track of last scroll var lastScroll = 0; var header = $("#header"); var headerfixed = $("#header-main-fixed"); var headerfixedbg = $(".header-bg"); var headerfixedtopbg = $(".top-header-bg"); var toTopOfPage = document.getElementById("gotop"); var goToTopExists = typeof toTopOfPage !== "undefined" && toTopOfPage !== null; $(window).scroll(function() { //Sets the current scroll position var st = $(this).scrollTop(); //Determines up-or-down scrolling if (st > lastScroll) { //Replace this with your function call for downward-scrolling if (st > 50) { header.addClass("header-top-fixed"); header.find(".header-top-row").addClass("dis-n"); headerfixedbg.addClass("header-bg-fixed"); headerfixed.addClass("header-main-fixed"); headerfixedtopbg.addClass("top-header-bg-fix"); if (goToTopExists) {toTopOfPage.style.display = "block";} } } else { //Replace this with your function call for upward-scrolling if (st < 50) { header.removeClass("header-top-fixed"); header.find(".header-top-row").removeClass("dis-n"); headerfixed.removeClass("header-main-fixed"); headerfixedbg.removeClass("header-bg-fixed"); headerfixedtopbg.removeClass("top-header-bg-fix"); if (goToTopExists) {toTopOfPage.style.display = "none";} } } //Updates scroll position lastScroll = st; }); //to the top of the page button $(".top-page").click(function() { document.body.scrollTop = 0; // For Chrome, Safari and Opera document.documentElement.scrollTop = 0; // For IE and Firefox }); // Bestseller owl slider script $("#nav-bestseller .next").click(function() { $("#owl-bestseller").trigger('owl.next'); }); $("#nav-bestseller .prev").click(function() { $("#owl-bestseller").trigger('owl.prev'); }); $("#owl-bestseller").owlCarousel({ // Most important owl features items: 4, itemsCustom: false, itemsDesktop: [1199, 3], itemsDesktopSmall: [980, 2], itemsTablet: [630, 1], itemsTabletSmall: false, itemsMobile: [479, 1], singleItem: false, itemsScaleUp: false, responsive: true, responsiveRefreshRate: 200, responsiveBaseWidth: window, autoPlay: false, stopOnHover: false, navigation: false }); // Summer sale owl slider script $("#nav-summer-sale .next").click(function() { $("#owl-summer-sale").trigger('owl.next'); }); $("#nav-summer-sale .prev").click(function() { $("#owl-summer-sale").trigger('owl.prev'); }); $("#owl-summer-sale").owlCarousel({ // Most important owl features items: 3, itemsCustom: false, itemsDesktop: [1199, 2], itemsDesktopSmall: [980, 2], itemsTablet: [630, 1], itemsTabletSmall: false, itemsMobile: [479, 1], singleItem: false, itemsScaleUp: false, responsive: true, responsiveRefreshRate: 200, responsiveBaseWidth: window, autoPlay: false, stopOnHover: false, navigation: false }); // iphone(ios) owl slider script $("#nav-child .next").click(function() { $("#owl-child").trigger('owl.next'); }); $("#nav-child .prev").click(function() { $("#owl-child").trigger('owl.prev'); }); $("#owl-child").owlCarousel({ // Most important owl features items: 3, itemsCustom: false, itemsDesktop: [1199, 2], itemsDesktopSmall: [980, 2], itemsTablet: [630, 1], itemsTabletSmall: false, itemsMobile: [479, 1], singleItem: false, itemsScaleUp: false, responsive: true, responsiveRefreshRate: 200, responsiveBaseWidth: window, autoPlay: false, stopOnHover: false, navigation: false }); // owl slider script $("#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'); }); $("#owl-new").owlCarousel({ // Most important owl features items: 4, itemsCustom: false, itemsDesktop: [1199, 3], itemsDesktopSmall: [980, 2], itemsTablet: [630, 1], itemsTabletSmall: false, itemsMobile: [479, 1], singleItem: false, itemsScaleUp: false, responsive: true, responsiveRefreshRate: 200, responsiveBaseWidth: window, autoPlay: false, stopOnHover: false, navigation: false }); $("#owl-featured").owlCarousel({ // Most important owl features items: 4, itemsCustom: false, itemsDesktop: [1199, 3], itemsDesktopSmall: [980, 2], itemsTablet: [630, 1], itemsTabletSmall: false, itemsMobile: [479, 1], singleItem: false, itemsScaleUp: false, responsive: true, responsiveRefreshRate: 200, responsiveBaseWidth: window, autoPlay: false, stopOnHover: false, navigation: false }); // owl slider script $("#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'); }); $("#owl-new2").owlCarousel({ // Most important owl features items: 3, itemsCustom: false, itemsDesktop: [1199, 2], itemsDesktopSmall: [980, 2], itemsTablet: [630, 1], itemsTabletSmall: false, itemsMobile: [479, 1], singleItem: false, itemsScaleUp: false, responsive: true, responsiveRefreshRate: 200, responsiveBaseWidth: window, autoPlay: false, stopOnHover: false, navigation: false }); $("#owl-featured2").owlCarousel({ // Most important owl features items: 3, itemsCustom: false, itemsDesktop: [1199, 2], itemsDesktopSmall: [980, 2], itemsTablet: [630, 1], itemsTabletSmall: false, itemsMobile: [479, 1], singleItem: false, itemsScaleUp: false, responsive: true, responsiveRefreshRate: 200, responsiveBaseWidth: window, autoPlay: false, stopOnHover: false, navigation: false }); $("#owl-partners").owlCarousel({ // Most important owl features items: 5, itemsCustom: false, itemsDesktop: [1199, 4], itemsDesktopSmall: [980, 3], itemsTablet: [630, 1], itemsTabletSmall: false, itemsMobile: [479, 1], singleItem: false, itemsScaleUp: false, responsive: true, responsiveRefreshRate: 200, responsiveBaseWidth: window, autoPlay: true, stopOnHover: false, navigation: false }); $("#owl-home-slider").owlCarousel({ // Most important owl features items: 1, itemsCustom: false, itemsDesktop: [1199, 1], itemsDesktopSmall: [980, 1], itemsTablet: [630, 1], itemsTabletSmall: false, itemsMobile: [479, 1], singleItem: false, itemsScaleUp: false, responsive: true, responsiveRefreshRate: 200, responsiveBaseWidth: window, autoPlay: true, stopOnHover: false, navigation: false }); $(function() { $('.dropdown').hover(function() { $(this).addClass('open'); }, function() { $(this).removeClass('open'); }); }); // jPages paginated blocks var $holder = $("body").find(".holder"); if (!$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 }); $('.revolution').revolution({ delay: 9000, startwidth: 1170, startheight: 500, hideThumbs: 10, fullWidth: "on", fullScreen: "on", navigationType: "none", navigationArrows: "solo", navigationStyle: "round", navigationHAlign: "center", navigationVAlign: "bottom", navigationHOffset: 30, navigationVOffset: 30, soloArrowLeftHalign: "left", soloArrowLeftValign: "center", soloArrowLeftHOffset: 20, soloArrowLeftVOffset: 0, soloArrowRightHalign: "right", soloArrowRightValign: "center", soloArrowRightHOffset: 20, soloArrowRightVOffset: 0, touchenabled: "on" }); $('.tool_tip').tooltip(); // Color Filter /*$(".colors li a").each(function() { $(this).css("background-color", "#" + $(this).attr("rel")).attr("href", "#" + $(this).attr("rel")); });*/ // Product zoom $('#product-zoom').elevateZoom({ zoomType: "inner", cursor: "crosshair", zoomWindowFadeIn: 500, zoomWindowFadeOut: 750 }); var $gallery = $('#gal1'); $gallery.find("a[data-image]").hover(function() { $(".product-media-details").removeClass("video"); var smallImage = $(this).attr("data-image"); var largeImage = $(this).attr("data-zoom-image"); var ez = $('#product-zoom').data('elevateZoom'); ez.swaptheimage(smallImage, largeImage); }); $gallery.find("a[data-video]").on("mouseover", function() { var $this = $(this), $details = $(".product-media-details"), $videoPlayer = $details.find(".product-video"); $videoPlayer.find("iframe").remove(); $videoPlayer.append('
'); var player = new YT.Player('player', { width: '100%', videoId: $this.data("video"), events: { 'onReady': function (event) { event.target.playVideo(); } } }); $details.addClass("video"); }); // Daily Deal CountDown Clock Settings var date = new Date().getTime(); // This example is just to show how this function works. var new_date = new Date(date + 86400000); // You can set your own time whenever you want. // var n = new_date.toUTCString(); // 'date' value is given in milliseconds. //alert(new_date) $(".time").countdown({ date: new_date, yearsAndMonths: true, leadingZero: true }); // Categories Menu Manipulations $(".ul-side-category li a").click(function() { var sm = $(this).next(); if (sm.hasClass("sub-category")) { if (sm.css("display") === "none") { $(this).next().slideDown(); } else { $(this).next().slideUp(); $(this).next().find(".sub-category").slideUp(); /*$(this).next().find(".categories-submenu").slideUp("normal", function() { $(this).parent().find(".icon-angle-down").removeClass("icon-angle-down").addClass("icon-angle-right"); });*/ } return false; } else { return true; } }); function toggleType() { if (!$("[name='customer[type]']").length) { return; } var type = $("[name='customer[type]']").val(), $customerType = $("#customer_customerType"), $options = $customerType.find("option"); if (type == "cpf") { $(".cpf").show().find(":input").attr("required", "required"); $(".cnpj").hide().find(":input").removeAttr("required"); $customerType.val( $options.filter(function() { return $(this).text() == "B2C" }).val() ); } else { $(".cnpj").show().find(":input:not(#check):not(#customer_taxationRegime)").attr("required", "required"); $(".cpf").hide().find(":input").removeAttr("required"); $customerType.val( $options.filter(function() { return $(this).text() == "B2B" }).val() ); } } $("[name='customer[type]']").on("change blur", function() { toggleType(); }); $(".cart-sumary .header-mini-cart").on('click', function(cart) { renderCartSummaryWithPrices(cart) }) $("#check").on("change click", function() { var isento = $(this).is(":checked"); if (isento) { $("#customer_cnpj_stateRegistration").addClass("readonly").attr("readonly", "readonly").val("ISENTO"); } else { $("#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 $this = $(this); $this.data("src", $this.attr("src")).attr("src", $this.data("hover")); }) .on("mouseleave", function(e) { var $this = $(this); $this.attr("src", $this.data("src")); }); $(".product-related-carousel").owlCarousel({ // Most important owl features items: 6, itemsCustom: false, itemsDesktop: [1199, 3], itemsDesktopSmall: [980, 2], itemsTablet: [630, 1], itemsTabletSmall: false, itemsMobile: [479, 1], singleItem: false, itemsScaleUp: false, responsive: true, responsiveRefreshRate: 200, responsiveBaseWidth: window, autoPlay: true, stopOnHover: true, navigation: false }); $(".product-related-nav .next").click(function() { $($(this).data("carousel")).trigger('owl.next'); }); $(".product-related-nav .prev").click(function() { $($(this).data("carousel")).trigger('owl.prev'); }); function removeMask(quantity) { quantity = quantity.replace(/\./g, ""); return parseFloat(quantity.replace(/,/g, '.')); } $(".flexy-cart-product-quantity, .input-number-inf") .on("focus", function(e) { var $this = $(this); $this.data("quantity", removeMask($this.val())); }) .on("blur", function(e) { var $this = $(this); if ($this.val() && $this.val() != $this.data("quantity")) { $this.trigger("change"); } else { $this.val($this.data("quantity")); } }); $("body").on("cart-success", ".flexy-add-to-cart, .flexy-add-to-booking", function(event, cart) { addQuantityItemToCart(cart); if(window.innerWidth < 991 || screen.width < 991) { alert("Produto adicionado ao carrinho!"); } }); $(document).ready(function() { (function($, CART) { $("body").off("cart-error"); $("body").on("cart-error", function(event, errorMessage) { const regex = /O produto (.+?) não possui estoque suficiente\. Atualmente possuímos apenas (\d+)/; const match = errorMessage.match(regex); if (match) { // Se você tem acesso a informações do produto no lado do Twig, use-as aqui const productName = ''; // Substitua por como você acessa o nome do produto no Twig alert(`O produto ${productName} não possui estoque suficiente.`); } else { alert(errorMessage); } }); })(jQuery, CART); }); $('#create-gift-list-form').on('submit', function() { $('#create-gift-list-button').attr('disabled', true); if ($(this).attr("data-sent")) { return false; } $(this).attr("data-sent", "data-sent"); }); function mask3decimals($value) { var $value = $value.toString(); if ($value.indexOf('.') > -1) { $value = Number($value).toFixed(3); $value = $value.replace(".", ","); } return $value; } function verifyStockAndTriggerChange(e, weight, currentField) { var stock = currentField.data("stock"); var weightWithoutMask = removeMask(weight); if (!verifyStockLimit(weightWithoutMask, stock)) { currentField.val(mask3decimals(stock)).trigger("change"); e.preventDefault(); e.stopImmediatePropagation(); return false; } return true; } var $inputWeight = $(".flexy-weight-mask"); $inputWeight.mask("#######0,000", { placeholder: "0,000", reverse: true }); var typingTimer; var doneTypingInterval = 1200; $inputWeight.on('keyup', function (event) { clearTimeout(typingTimer); typingTimer = setTimeout(function() { if(verifyStockAndTriggerChange(event, $(this).val(), $(this))){ $(this).trigger("blur"); } }, doneTypingInterval); }); $inputWeight.on('keydown', function (event) { clearTimeout(typingTimer); }); $(".stock-verified").on("change keypress keyup keydown", function(e) { var $this = $(this); if (!verifyStockLimit(Number($this.val()), $this.data("stock"))) { $this.val(mask3decimals($this.data("stock"))).trigger("change"); e.preventDefault(); e.stopImmediatePropagation(); } }); // $(".grid-open .input-number-inf").on("change", function() { // totalizeGrid(); // }); // $(".grid-closed .flexy-input-integer").on("change", function() { // totalizeGrid(); // }); // totalizeGrid(); toggleType(); addQuantityItemToCart(CART); // renderCartSummary(CART); }); async function updateCartInformation(cart) { const cartUpdatedResponse = await fetch('/checkout/current-cart'); const cartUpdated = await cartUpdatedResponse.json(); CART = cartUpdated; Object.assign(cart, CART); } new WOW().init(); })(jQuery, CART); (function() { var additionalIds = []; var additionalVariantIds = new Set([]); /** * * @param variantId * @returns {number} */ function getAdditionalVariantIndex(variantId) { return additionalIds.indexOf(variantId); } /** * * @param variantId */ function addAdditional(variantId) { additionalIds.push(variantId); } /** * * @param variantId */ function removeAdditional(variantId) { additionalIds.splice(getAdditionalVariantIndex(variantId), 1); } /** * * @param variantId * @returns {boolean} */ function hasAdditional(variantId) { return getAdditionalVariantIndex(variantId) > -1; } $(function() { $(".additional-add-to-cart").on("click", function() { var $this = $(this), variantId = $this.data("variant-id"); if (hasAdditional(variantId)) { removeAdditional(variantId); alert("Produto removido!"); } else { addAdditional(variantId); alert("Produto adicionado!"); } $(".main_cart_add").data("additional-variant-ids", additionalIds); }); }); $(function() { $(".additional-to-cart").on("click", function() { var additionId = $(this).data("addition-id"); additionalVariantIds.add(additionId); $(".flexy-add-to-cart, .flexy-add-to-booking").one("cart-error", function() { additionalVariantIds.delete(additionId); }); }); }); function searchToggle(){ $(".search-box").animate({ opacity: "toggle" }, 500, function() { // Animation complete. }); $(".search-modal-background").animate({ opacity: "toggle" }, 500, function() { // Animation complete. }); } $(function() { $( ".search-box-toggle" ).click(function() { searchToggle(); $(".search-input").focus(); }); $( ".search-modal-background" ).click(function() { searchToggle(); }); }); $(function() { $(".coupon-validate").on( "keyup", function(e) { $(this).val($(this).val().replace(/[^0-9a-zA-Z_]/g, '')); } ); }); $(function () { $("#zipCodeCart").on( "keyup", function (e) { if ($(this).val().length === 9) { container = $('.cep_validate'); var url = "https://viacep.com.br/ws/" + $(this).val() + "/json/"; var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var response = JSON.parse(xmlhttp.responseText); if (response.erro) { $('#calculation_cep').attr('disabled', true); container.html('
Este CEP não existe.
Favor informe um CEP válido
'); $('.shipping-estimate').hide(); return false; } } if (response.logradouro) { $('.cep_validate').html(''); $('#calculation_cep').attr('disabled', false); $('#calculation_cep').focus(); } }; xmlhttp.open("GET", url, true); xmlhttp.send(); } if ($(this).val().length === 0) { $('.cep_validate').html(''); } } ); }); $(function() { $( "#zipCode" ).click(function() { var currentPath = window.location.pathname; if(currentPath.indexOf("quote") !== -1) { var postCode = $('.flexy-input-postcode').val(); var quoteUrl = [location.protocol, '//', location.host, location.pathname].join('') + '?zipCode=' + postCode; var observationUrl = ''; $('.f2-quote-observation').each(function () { var quoteObservation = $(this).data('observation'); var quoteMessage = $(this).val(); observationUrl += '&' + quoteObservation + '=' + quoteMessage; }); window.location = quoteUrl + observationUrl; } }); }); $(function() { $( ".copy-to-clipboard" ).click(function() { let $this = $(this) let text = $this.data('text') let dummy = document.createElement("input") document.body.appendChild(dummy) dummy.setAttribute("id", "dummy_id") document.getElementById("dummy_id").value = text dummy.select() document.execCommand("copy") document.body.removeChild(dummy) let icon = $this.find('.fa-check') if (!icon.length) { icon = document.createElement('span') $this.append(icon) $(icon).addClass('fa fa-check') } $this.fadeOut(300) .fadeIn(300) .prop('title', 'Copiado!') }); }); $(function() { $(".payment-box .nav-tabs [role=tab]").on("click", function() { let paymentMethod = $("[name='checkout[paymentMethod][0][name]']:checked").val() let creditCardRegex = new RegExp("payment\.method\.creditcard\..+") if (!creditCardRegex.test(paymentMethod)) { $("#installments-tax").hide() } }); }); })();