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 += `
' + 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(`