Your cart is empty

Add exclusive wines to your collection

Continue shopping
+ shipping.toFixed(2)}
${translations.total} $${total.toFixed(2)}
${translations.checkout}

${translations.secure_payment}

${translations.delivery_days}

${translations.return_policy}

`; } function updateQuantity(index, delta) { cartItems[index].quantity = Math.max(1, cartItems[index].quantity + delta); localStorage.setItem('cart', JSON.stringify(cartItems)); renderCart(); updateCartCount(); window.dispatchEvent(new Event('cartUpdated')); } function updateCartCount() { try { const totalItems = cartItems.reduce((sum, item) => sum + (item.quantity || 1), 0); const cartBadge = document.getElementById('cartBadge'); const cartBadgeMobile = document.getElementById('cartBadgeMobile'); const cartBadgeMobileHeader = document.getElementById('cartBadgeMobileHeader'); const navCartMobileHeader = document.getElementById('navCartMobileHeader'); if (cartBadge) { cartBadge.textContent = totalItems; if (totalItems > 0) { // Force display first cartBadge.style.display = 'flex'; cartBadge.style.opacity = '1'; cartBadge.style.transform = 'scale(1)'; // Add animation class for smooth appearance cartBadge.classList.add('cart-badge-animate'); // Remove animation class after animation completes, but keep badge visible setTimeout(() => { cartBadge.classList.remove('cart-badge-animate'); cartBadge.style.opacity = '1'; cartBadge.style.transform = 'scale(1)'; }, 300); } else { cartBadge.style.display = 'none'; } } if (cartBadgeMobile) { cartBadgeMobile.textContent = totalItems; if (totalItems > 0) { cartBadgeMobile.style.display = 'flex'; } else { cartBadgeMobile.style.display = 'none'; } } // Update mobile header cart icon if (navCartMobileHeader) { if (totalItems > 0) { navCartMobileHeader.style.display = 'flex'; navCartMobileHeader.classList.add('active'); } else { navCartMobileHeader.style.display = 'none'; navCartMobileHeader.classList.remove('active'); } } if (cartBadgeMobileHeader) { cartBadgeMobileHeader.textContent = totalItems; if (totalItems > 0) { cartBadgeMobileHeader.style.display = 'flex'; } else { cartBadgeMobileHeader.style.display = 'none'; } } } catch (e) { console.warn('Error updating cart count:', e); } } function removePromo() { hidePromoError(); promoApplied = false; currentPromoCode = null; localStorage.removeItem('promoApplied'); localStorage.removeItem('promoCode'); renderCart(); } function removeItem(index) { cartItems.splice(index, 1); localStorage.setItem('cart', JSON.stringify(cartItems)); renderCart(); updateCartCount(); window.dispatchEvent(new Event('cartUpdated')); } async function applyPromo() { const promoCodeInput = document.getElementById('promoCode'); const promoCode = promoCodeInput.value.trim().toUpperCase(); if (!promoCode) { return; } try { const apiPath = basePath + '/admin/api/promo-codes.php'; const response = await fetch(`${apiPath}?code=${encodeURIComponent(promoCode)}`); if (!response.ok) { throw new Error('Network response was not ok'); } const data = await response.json(); if (data.error || !data.id) { showPromoError(lang === 'es' ? 'Código promocional inválido o expirado' : 'Invalid or expired promo code'); promoCodeInput.value = ''; promoApplied = false; currentPromoCode = null; localStorage.removeItem('promoApplied'); localStorage.removeItem('promoCode'); renderCart(); return; } // Validate minimum order amount const subtotal = cartItems.reduce((sum, item) => sum + (item.price * item.quantity), 0); if (data.min_order_amount && parseFloat(data.min_order_amount) > 0 && subtotal < parseFloat(data.min_order_amount)) { showPromoError(lang === 'es' ? `El pedido mínimo para este código es $${parseFloat(data.min_order_amount).toFixed(2)}. Su pedido actual es $${subtotal.toFixed(2)}.` : `Minimum order amount for this code is $${parseFloat(data.min_order_amount).toFixed(2)}. Your current order is $${subtotal.toFixed(2)}.`); promoCodeInput.value = ''; promoApplied = false; currentPromoCode = null; localStorage.removeItem('promoApplied'); localStorage.removeItem('promoCode'); renderCart(); return; } promoApplied = true; currentPromoCode = data; localStorage.setItem('promoApplied', 'true'); localStorage.setItem('promoCode', JSON.stringify(data)); renderCart(); } catch (error) { console.error('Error validating promo code:', error); showPromoError(lang === 'es' ? 'Error al validar el código promocional. Por favor, intente de nuevo.' : 'Error validating promo code. Please try again.'); promoCodeInput.value = ''; } } // Initialize document.addEventListener('DOMContentLoaded', () => { promoApplied = localStorage.getItem('promoApplied') === 'true'; renderCart(); updateCartCount(); }); // Listen for storage changes window.addEventListener('storage', () => { cartItems = JSON.parse(localStorage.getItem('cart') || '[]'); renderCart(); updateCartCount(); }); window.addEventListener('cartUpdated', updateCartCount); // Mobile menu toggle document.addEventListener('DOMContentLoaded', function () { const mobileMenuToggle = document.getElementById('mobileMenuToggle'); const mobileMenu = document.getElementById('mobileMenu'); const mobileMenuClose = document.getElementById('mobileMenuClose'); if (mobileMenuToggle && mobileMenu) { mobileMenuToggle.addEventListener('click', () => { mobileMenu.classList.add('active'); document.body.style.overflow = 'hidden'; }); } if (mobileMenuClose && mobileMenu) { mobileMenuClose.addEventListener('click', () => { mobileMenu.classList.remove('active'); document.body.style.overflow = ''; }); } // Close mobile menu when clicking on a link if (mobileMenu) { const mobileMenuLinks = mobileMenu.querySelectorAll('a'); mobileMenuLinks.forEach(link => { link.addEventListener('click', () => { mobileMenu.classList.remove('active'); document.body.style.overflow = ''; }); }); } // Close mobile menu when clicking outside if (mobileMenu) { mobileMenu.addEventListener('click', (e) => { if (e.target === mobileMenu) { mobileMenu.classList.remove('active'); document.body.style.overflow = ''; } }); } });