var rtl = ($('html').attr('dir') === 'rtl'); $('.toggle-search').click(function () { $('.wrap-width-search').toggleClass('active'); $('#search-block').toggleClass('active'); }); $('#side-menu').offcanvas({ modifiers: rtl ? 'right' : 'left' + ', overlay', triggerButton: '#show-sideMenu', closeButtonClass: "menu-close-side", }); $('#side-cart').offcanvas({ modifiers: rtl ? 'left' : 'right' + ', overlay', triggerButton: '#show-side-cart', closeButtonClass: "cart-close-side" }); $(document).on('click', '.quick-view', function () { var $this = $(this), id = $this.data('id'), target = $('#__loading'), html = '', text = $this.html(), modal = $('.quick-view-modal'); $this.html('').prop('disabled', true); zid.store.product.fetch(id).then(function (response) { var product = response.data.product, images = '', rating = '', discount = '', rating_total_count = ''; var selected_product = product ?? product.selected_product; var product_media = selected_product.media ?? selected_product.images; $.each(product_media, function (key, item) { if (!item['alt_text'] || item['alt_text'].toUpperCase() !== 'COLOR') { var isVideo = (item['link'] && item['provider'] == 'youtube') ? 'product-video' : ''; images += `
  • '+ item['alt_text'] +' `; } images += '
  • '; } }); if (product.rating) { rating += ``; let rating_average = product.rating ? product.rating.average : 0; let ratingAvg = Math.round(parseFloat(rating_average)); for (var i = 1; i <= 5; i++) { rating += ``; } rating += ``; rating_total_count += window.translations.product_reviews_x_count_start + ' ' + product.rating.total_count + ' ' + window.translations.product_reviews_x_count; } else { rating += ''; for (var i = 1; i <= 5; i++) { rating += ''; } rating += ''; rating_total_count += window.translations.no_product_reviews; } if (response.status === "success") { html += ``; target.html(html).promise().done(function () { $('.quick-view-modal').modal('show'); $('.quick-view-modal').on('shown.bs.modal', function (event) { $('#qv_product_images').slick({ rtl: !(window.appDirection === 'ltr'), slidesToShow:1, arrows: false, dots: true, infinite: true, adaptiveHeight: true, autoplaySpeed: 5000, autoplay: false, rtl:(window.appDirection==='rtl') ? true : false, }); }); $('.quick-view-modal').on('hide.bs.modal', function (event) { $('#__loading').html(''); }); if (window.hasWishlist) { fetchWishlist(); } }); $('#qv_product_images').on('afterChange', function(event, slick, currentSlide) { var qvSlider = $('.quick-view-modal li.product-video'); if (qvSlider.hasClass('video-play')) { qvSlider.find('iframe').remove(); qvSlider.find('.play-btn').show(); qvSlider.removeClass('video-play'); } }); $this.html(text).prop('disabled', false); } else { alert('Error load product'); } }); }); function createCartProduct(product) { let html_item = ''; html_item += `
  • ${product.name}

    `; var new_price = Number(product.total).toFixed(2) + ' ' + window.cart_currency ; if (product.total_before) { var old_price = Number(product.total_before).toFixed(2) + ' ' + window.cart_currency; html_item += ` ${old_price} ${new_price} `; } else { html_item += ` ${new_price} `; } html_item += `
  • `; ` `; return html_item; } function fetchCart() { $('#additional-cart').html(''); $('.side-cart-items').removeClass('d-none'); var empty_text = window.translations.empty_cart; zid.store.cart.fetch().then(function (response) { if (response.status === "success") { var cart = response.data.cart, html_item = '', total_html = ''; let total = 0; let total_string = '0.00 ' + cart_currency; var cart_error = false; var count_products = 0; var products_total = 0; var total_discount = 0; displayActivePaymentSessionBar(cart); if (cart.products_count > 0) { cart.products.map(function (product) { if (product.bundle_name) { product.product_x.forEach((product) => { count_products = (count_products + product.quantity); product_beforeSale = product.total_before ?? product.total; products_total = Number(products_total) + Number(product_beforeSale); if (product.total_before) { calc_discount = (product.total_before - product.total); if (calc_discount > 0) { total_discount = Number(total_discount) + Number(calc_discount); } } html_item += createCartProduct(product); if(product.error_message) { cart_error = true; } }) product.product_y.forEach((product) => { count_products = (count_products + product.quantity); product_beforeSale = product.total_before ?? product.total; products_total = Number(products_total) + Number(product_beforeSale); if (product.total_before) { calc_discount = (product.total_before - product.total); if (calc_discount > 0) { total_discount = Number(total_discount) + Number(calc_discount); } } html_item += createCartProduct(product); if(product.error_message) { cart_error = true; } }) } else { count_products = (count_products + product.quantity); product_beforeSale = product.total_before ?? product.total; products_total = Number(products_total) + Number(product_beforeSale); if (product.total_before) { calc_discount = (product.total_before - product.total); if (calc_discount > 0) { total_discount = Number(total_discount) + Number(calc_discount); } } html_item += createCartProduct(product); if(product.error_message) { cart_error = true; } } }); var cartTotal; if (cart.totals) { cart.totals.forEach(CartTotals => { if (CartTotals.code === 'total') { cartTotal = CartTotals.value; total_string = Number(CartTotals.value).toFixed(2); total_string = total_string + ' ' + cart_currency; } if (CartTotals.code === 'sub_totals' || CartTotals.code === 'sub_totals_before_vat') { sub_totals = Number(CartTotals.value).toFixed(2) + ' ' + cart_currency; } }) } $('#cart-side-totals > #sub_totals .number').html(Number(products_total).toFixed(2) +' '+ cart_currency); $('#cart-side-totals > #discount_value .number').html(Number(total_discount).toFixed(2) +' '+ cart_currency); $('#cart-side-totals > #total .number').html(total_string); $('.side-cart-items').html(html_item).fadeTo("slow", 1).css('pointer-events', ''); $('.side-cart-products, .footer-side-cart').removeClass('d-none'); } else { $('#additional-cart').html('

    ' + empty_text + '

    '); $('.side-cart-items').html(''); $('.cart-count').html(0); $('.side-cart-products, .footer-side-cart').addClass('d-none'); if (cart.gift_card_details) { zid.store.cart.removeGiftCard(); } } $('.cart-count').html(count_products); if (cart_error == true) { $('.footer-side-cart .cart-page').prop('href', '/cart/view'); } // shipping $('#side-cart .cart-shipping-notice').addClass('d-none'); if (cart.discount_rules && cartTotal) { cart.discount_rules.forEach(rule => { if (rule.code === 'free_shipping') { $('#side-cart .cart-shipping-notice').removeClass('d-none'); rule.conditions.forEach(condition => { if (condition.field === "subtotal" && condition.operator === "between_inclusive") { createCartFreeShippingSection(cartTotal, condition, cart.coupon); } }) } }) } else { $('#side-cart .cart-shipping-notice').addClass('d-none') } //coupon var $couponBtn = $('.apply_coupon'); var $couponCode = $('.coupon-code'); if (cart.coupon) { var coupon_value = Number(cart.coupon.discount_amount).toFixed(2); $couponBtn.text(window.translations.remove_coupon); $couponCode.val(cart.coupon.code); $couponCode.attr('disabled', true); $couponBtn.addClass('remove-coupon'); if (window.vat_percentage) { coupon_value = Number(coupon_value) + (Number(coupon_value) * Number(window.vat_percentage)); } total_discount = Number(total_discount) + Number(coupon_value); total_discount = total_discount.toFixed(2) + ' ' + cart_currency if (cart.coupon.free_shipping) { total_discount = total_discount + ' + ' + window.translations.coupon_free_shipping } $('#cart-side-totals > #discount_value .number').html(total_discount); $couponBtn.off().on('click', () => { $couponCode.val(''); removeCoupon() }); } else { $('#cart-side-totals > #discount_value .number').html(Number(total_discount).toFixed(2) + ' ' + cart_currency); $couponBtn.removeClass('remove-coupon'); $couponCode.attr('disabled', false); $couponBtn.text(window.translations.add_coupon); $couponBtn.off().on('click', (e) => { addCoupon($couponCode.val(), e) }); } if (total_discount == 0 && !cart.coupon) { $('#cart-side-totals > #discount_value').addClass('d-none'); } else { $('#cart-side-totals > #discount_value').removeClass('d-none'); } if (cart.gift_card_details) { $('#is_gift_checkbox').prop('checked', true); } else { $('#is_gift_checkbox').prop('checked', false); } } else { alert('Error Cart'); } }); } function createCartFreeShippingSection(cartTotal, condition, cartCoupon){ let free_shipping_text = window.translations.free_shipping_description; let completedPercentage = 100; let $free_shipping_rules = $('#side-cart .shipping-alert'); $free_shipping_rules.empty(); if (cartCoupon && cartCoupon.free_shipping == true) { coupon_free_shipping = true; } else { coupon_free_shipping = false; } var free_shipping_min = condition.value[0]; if (cartTotal < free_shipping_min && coupon_free_shipping == false) { let difference = (free_shipping_min - cartTotal).toFixed(2) + ' ' + window.cart_currency; completedPercentage = Math.round((cartTotal / free_shipping_min) * 100); let shipping_text_replaced = free_shipping_text.replace("{X}", `${difference}`); $free_shipping_rules.append('' + shipping_text_replaced + ''); } else { $free_shipping_rules.append('' + window.translations.free_shipping + ''); } $('#side-cart #cart-shipping').removeClass('d-none'); $('#side-cart .minimog-progress-bar').css('width', completedPercentage + '%'); $('#side-cart .cart-shipping-notice').removeClass('d-none'); if (condition.value[1] && cartTotal > condition.value[1]){ $('#side-cart #cart-shipping').addClass('d-none'); } } function addCoupon(coupon_code) { var $couponBtn = $('.apply_coupon'); if (coupon_code.trim().length !== 0) { var $actions = $('.footer-side-cart'); $actions.fadeTo('slow', 0.3); $couponBtn.html(''); zid.store.cart.redeemCoupon(coupon_code).then((response) => { $actions.fadeTo('slow', 1); if (response.status === 'success') { toastr.success(window.translations.coupon_added, null) fetchCart(); } else { toastr.error(response?.data?.message ?? window.translations.sorry); $couponBtn.html(window.translations.add_coupon); } }) } else { toastr.error(window.translations.coupon_discount_enter); } } function removeCoupon() { var $actions = $('.footer-side-cart'); $actions.fadeTo('slow', 0.3); var $couponBtn = $('.apply_coupon'); $couponBtn.html(''); zid.store.cart.removeCoupon().then((response) => { $actions.fadeTo('slow', 1); if (response.status === 'success') { toastr.success(window.translations.coupon_remove, null) fetchCart(); } else { toastr.error(response?.data?.message ?? window.translations.sorry); $couponBtn.html(window.translations.remove_coupon); } }) } function removeItem(cart_product_id, product_id) { $('.side-cart-items li#product_' + cart_product_id + ' .remove').html(''); zid.store.cart.removeProduct(cart_product_id, product_id).then(function (response) { if (response.status === 'success') { fetchCart(); } }); } $('#show-side-cart').click(function (e) { fetchCart(); }); $('#show-search').click(function (e) { $('.header-search-form').slideToggle(); }); $('#show-lang').click(function (e) { $('#langCurrecyModal').modal('toggle'); }); $(".is-gift-label #is_gift_checkbox").change(function() { if(this.checked) { $('.footer-side-cart a.cart-page').html(''); if (!$('body').hasClass("cart-view")) { window.location.href = "/cart/view#gift"; } else { $(".gift-card > button").trigger("click"); } } }); $(document).delegate('.btn-number', 'click', function (e) { e.preventDefault(); var fieldName = $(this).attr('data-field'), type = $(this).attr('data-type'), input = $(this).parent().find("input[name='" + fieldName + "']"), currentVal = parseInt(input.val()); if (!isNaN(currentVal)) { if (type == 'minus') { if (currentVal > input.attr('min')) { input.val(currentVal - 1).change(); } if (parseInt(input.val()) == input.attr('min')) { $(this).attr('disabled', true); } } else if (type == 'plus') { if (currentVal < input.attr('max')) { input.val(currentVal + 1).change(); } if (parseInt(input.val()) == input.attr('max')) { $(this).attr('disabled', true); } } } else { input.val(0); } }); $(document).delegate('.input-number', 'focusin', function (e) { $(this).data('oldValue', $(this).val()); }); $(document).delegate('.input-number', 'change', function (e) { var minValue = parseInt($(this).attr('min')), maxValue = parseInt($(this).attr('max')), valueCurrent = parseInt($(this).val()); var name = $(this).attr('name'); if (valueCurrent >= minValue) { $(this).parent().find(".btn-number[data-type='minus'][data-field='" + name + "']").removeAttr('disabled') } else { alert('Sorry, the minimum value was reached'); $(this).val($(this).data('oldValue')); } if (valueCurrent <= maxValue) { $(this).parent().find(".btn-number[data-type='plus'][data-field='" + name + "']").removeAttr('disabled') } else { alert('Sorry, the maximum value was reached'); $(this).val($(this).data('oldValue')); } }); $(document).delegate('input-number', 'keydown', function (e) { // Allow: backspace, delete, tab, escape, enter and . if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 190]) !== -1 || // Allow: Ctrl+A (e.keyCode == 65 && e.ctrlKey === true) || // Allow: home, end, left, right (e.keyCode >= 35 && e.keyCode <= 39)) { // let it happen, don't do anything return; } // Ensure that it is a number and stop the keypress if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) { e.preventDefault(); } }); function addToQCart(ele, id) { var qty = $(ele).parent().find('.block-p-qty input').val() ?? 1, text = $(ele).html(); $(ele).html(''); addToCart(id, qty, function (response) { if(response.status == 'success') { var countCartProducts = response.data.cart.products_count; if (window.minAutoCartOpen && countCartProducts >= window.minAutoCartOpen) { $('#show-side-cart').click(); } else { fetchCart(); toastr.success(window.translations.cart_added_success); } $('.quick-view-modal.show').modal('hide'); } else { toastr.error(''+response.data.message+''); } $(ele).html(text); }); } function removeSideMenu() { $('.menu-close-side').trigger('click'); } $('.header').stickybits({ useStickyClasses: true, customVerticalPosition: true }); function copyLink(url, element) { var $this = $(element), text = $this.html(); navigator.clipboard.writeText(url); $this.html('').prop('disabled', true); setTimeout(function () { $this.html(text).prop('disabled', false); }, 3000); } function copyCode(Element, code) { $(Element).find("span").addClass('d-none'); $(Element).find("i").removeClass('d-none'); setTimeout(function(){ $(Element).find("i").addClass('d-none'); $(Element).find("span").removeClass('d-none'); navigator.clipboard.writeText(code); var $temp = $(""); $("body").append($temp); $temp.val(code).select(); document.execCommand("copy"); $temp.remove(); toastr.success(window.translations.save); },500); } fetchCart(); document.addEventListener("DOMContentLoaded", function() { if (window.hasWishlist) { fetchWishlist(); } }); $(document).on('click', '.add-to-wishlist', function(event) { event.stopPropagation(); event.preventDefault(); var wishlistBtn = $(this).parent(); var productID = $(this).parents('.product-wishlist').attr('data-id') ?? null; if (!productID || $(this).hasClass('guest-wishlist')) { var loginLink = '' +window.translations.login+''; var loginText = window.translations.wishlist_notlogin, loginText = loginText.replace("{X}", loginLink); toastr.error(`
    ${loginText}
    `); return false; } $(wishlistBtn).find('.wishlist-loading').removeClass('d-none').addClass('d-flex'); $(wishlistBtn).find('.wishlist-icon-wrapper').addClass('d-none').removeClass('d-flex'); zid.store.customer.addToWishlist(productID).then((response) => { if (response.status === "success") { toastr.success(response.data.message); toggleWishlistState(productID, true); $('.wishlist-count').html(response.data.wishlist.total).removeClass('d-none'); } else { toastr.error(response.data.message); } $(wishlistBtn).find('.wishlist-loading').removeClass('d-flex').addClass('d-none'); }); }); $(document).on('click', '.remove-from-wishlist', function(event) { event.stopPropagation(); event.preventDefault(); var wishlistBtn = $(this).parent(); var productID = $(this).parents('.product-wishlist').attr('data-id') ?? null; if (!productID) { var loginLink = '' +window.translations.login+''; var loginText = window.translations.wishlist_notlogin, loginText = loginText.replace("{X}", loginLink); toastr.error(`
    ${loginText}
    `); return false; } $(wishlistBtn).find('.wishlist-loading').removeClass('d-none').addClass('d-flex'); $(wishlistBtn).find('.wishlist-icon-wrapper').addClass('d-none').removeClass('d-flex'); zid.store.customer.removeFromWishlist(productID).then((response) => { if (response.status === "success") { toastr.success(response.data.message); toggleWishlistState(productID, false); $('.wishlist-count').html(response.data.wishlist.total).removeClass('d-none'); if(response.data.wishlist.total == 0) { $('.wishlist-count').html(0).addClass('d-none'); } } else { toastr.error(response.data.message); } $(wishlistBtn).find('.wishlist-loading').removeClass('d-flex').addClass('d-none'); }); }); zid.store.loyalty.getRedemptionMethods().then(function (response) { if(response.status == 'success'){ $('.footer-side-cart .cart-page').prop('href', '/cart/view'); } }); $(document).on('click', '.footer-side-cart a.cart-page', function () { $('.footer-side-cart a.cart-page').html(''); }); $(document).on('click', '.btn-checkout', function () { if ($(this).attr('href') !== '#!') { $('.btn-checkout').html(''); } }); $("video[autoplay]").each(function () { this.play(); }); /* window.onscroll = function(){CheckIfTop()}; function CheckIfTop(){ if(window.scrollY==0){ $('.top-banner-slider').slick('refresh'); } } */ $(document).mouseup(function(e) { var toastContainer = $("#toast-container"); if (!toastContainer.is(e.target) && toastContainer.has(e.target).length === 0) { $('button.toast-close-button').click(); } }); $(window).bind("pageshow", function(event) { if ($('.footer-side-cart a.cart-page > .loading-icon').length) { $('.footer-side-cart a.cart-page').html(`${window.translations.mini_cart_btn}`); } if ($('.sticky-cart .btn-checkout > .loading-icon').length) { $('.sticky-cart .btn-checkout').html(`${window.translations.mini_cart_btn}`); } }); $(document).on('click', '.list-side-menu .has-submenu', function () { $('.list-side-menu .collapse.show').collapse('hide'); }); $(document).on('click', '.quick-cart', function () { let product_id = $(this).attr('data-id'); var $this = $(this); var text = $this.html(); $this.html('').prop('disabled', true); addToCart(product_id, 1, function (response) { if(response.status == 'success') { var countCartProducts = response.data.cart.products_count; if (window.minAutoCartOpen && countCartProducts >= window.minAutoCartOpen) { $('#show-side-cart').click(); } else { fetchCart(); toastr.success(window.translations.cart_added_success); } } else { toastr.error(''+response.data.message+''); } $this.html(text).prop('disabled', false); }); }) $(document).on('click', '.slider-home .btn-primary', function () { if($(this).closest('a').attr("href") !== '#!') { var BtnWidth = $(this).width(); var BtnHeight = $(this).height(); $(this).children('span').hide(); $(this).width(BtnWidth).height(BtnHeight); if($(this).find('.loading-icon').length == 0) { $(this).append(''); } } }) function updateMiniCartProduct(cart_product_id, quantity, product_id) { $('.side-cart-items').fadeTo('slow', 0.3).css('pointer-events', 'none'); zid.store.cart.updateProduct(cart_product_id, quantity, product_id).then(function (response) { if (response.status === 'success') { fetchCart(); } else { toastr.error('
    '+response.data.message+'
    '); fetchCart(); } }) } function MenuCategoriesLink() { var menu_categories = []; $.ajax({ url: "/api/v1/categories", type: 'GET', dataType: 'json', success: function(categories) { categoriesList = categories.data.categories; $(categoriesList).each((index, category) => { menu_categories[category.id] = {}; menu_categories[category.id]["name"] = category.name; menu_categories[category.id]["image"] = category.image; if (category.sub_categories.length > 0) { menu_categories[category.id]["sub"] = category.sub_categories; $(category.sub_categories).each((sub_index, sub_category) => { menu_categories[sub_category.id] = {}; menu_categories[sub_category.id]["name"] = sub_category.name; menu_categories[sub_category.id]["image"] = sub_category.image; }); } }); if (menu_categories.length > 0) { if($('.side-menu-content .list-side-menu').hasClass('custom-categories')) { if($('.side-menu-content .list-side-menu').hasClass('show-categories-image')) { var showImagesIcons = true; } $('.list-side-menu .category-link').each(function(){ var categoryId = $(this).attr('id').split('cat_')[1]; if (menu_categories[categoryId]) { $('.menu-link.category-link#cat_'+ categoryId +' .main-category > span').text(menu_categories[categoryId]["name"]); if (showImagesIcons && menu_categories[categoryId]["image"]) { $('.menu-link.category-link#cat_'+ categoryId +' .categories-icon').attr('style','background-image: url("'+ menu_categories[categoryId]["image"] +'"').removeClass('svg-icon').addClass('categories-icon'); } if (menu_categories[categoryId]["sub"]) { $(this).addClass('with-categories'); var sublist = ''; $(sublist).insertAfter(this); } } }); } } } }); } MenuCategoriesLink();