Tu Carrito

14
Pabellón Vegetariano ⭐

Pabellón Vegetariano ⭐

PEN 28.90 c/u

1

PEN 28.90

La Arepa Taco

La Arepa Taco

PEN 28.50 c/u

12

PEN 342.00

🥇 COMBO REINA PEPIADA + BEBIDA

🥇 COMBO REINA PEPIADA + BEBIDA

PEN 29.90 c/u

1

PEN 29.90

Sabor Venezolano en Cada Mordisco

Las mejores arepas, hechas con amor y los ingredientes más frescos, directo a tu puerta en Lima.

Manos preparando masa de arepa

La Pasión por las Arepas Vive en Lima

ArepaCafeLima nació del amor por los sabores auténticos de Venezuela y el deseo de compartir esa tradición culinaria con la vibrante ciudad de Lima. Creemos en la calidad por encima de todo: nuestras arepas se elaboran diariamente con masa de maíz fresca y se rellenan con ingredientes seleccionados para ofrecerte una experiencia inigualable.

Desde la primera vez que pruebas una de nuestras creaciones, sentirás el cariño y la dedicación en cada bocado. Hacemos que disfrutar de la auténtica comida venezolana sea más fácil que nunca con nuestro servicio de entrega rápido y confiable en toda la ciudad.

Explora Nuestro Menú

Entrega Rápida y Segura en Lima

Disfruta de tus arepas favoritas sin salir de casa. Te llevamos el sabor de Venezuela a los distritos que amas.

Nuestras Zonas de Reparto

  • Surquillo
  • Barranco
  • Miraflores
  • San Isidro
  • Lince
  • Jesús María
  • San Luis
  • San Borja
  • La Molina
  • Surco

¿No ves tu distrito? Contáctanos por WhatsApp, ¡podríamos estar expandiéndonos pronto!

Mapa de zonas de entrega en Lima

Nuestro Proceso de Pedido es Sencillo

Elige tus Favoritos

Navega por nuestro menú y añade las arepas, acompañamientos y bebidas que más te apetezcan.

Pide por WhatsApp

Haz clic en el botón de WhatsApp o en el checkout para enviarnos tu pedido de forma rápida y sencilla.

Recibe tu Pedido

Nuestro equipo de delivery te entregará tu pedido caliente y fresco en el menor tiempo posible.

¡Únete al Club Arepa y Disfruta de Beneficios Exclusivos!

Conviértete en miembro de Arepa Club y sé recompensado por tu amor por las arepas. ¡Cada sol gastado te acerca a deliciosos premios!

¡Bienvenido al Club!

Recibe

50 Puntos

¡Solo por registrarte!

Gana Puntos

1 Sol Gastado = 1 Punto

(Excluye costos de envío)

Canjea tus Recompensas

100 Pts: Salsa o Bebida Gratis

250 Pts: Extra de Queso Gratis

500 Pts: Arepa Clásica Gratis

¡Sube de Nivel con Nuestro Programa VIP!

0-4

Órdenes/Mes

Amante de la Arepa

5-9

Órdenes/Mes

Fan de la Arepa

10+

Órdenes/Mes

Arepa VIP

¡Cada nivel desbloquea recompensas y sorpresas adicionales! Revisa tu historial de pedidos para ver tu progreso.

Comparte el Sabor, Gana Recompensas

¿Tienes amigos que aman las arepas tanto como tú? ¡Invítalos a probar ArepaCafeLima y ambos ganarán!

Amigos compartiendo arepas y ganando recompensas

¿Cómo Funciona?

1. Comparte tu código de referido único con tus amigos.

2. Tu amigo realiza su primer pedido usando tu código.

3. ¡Ambos reciben una recompensa! (Ej: Salsa Gratis, Bebida o S/5 de Crédito)

Lo Que Dicen Nuestros Clientes

La satisfacción de nuestros clientes es nuestra mayor motivación. ¡Mira algunas de sus experiencias!

Cliente Satisfecha 1

"¡Simplemente las mejores arepas que he probado fuera de Venezuela! La Reina Pepiada es mi favorita. La entrega siempre es puntual y la comida llega caliente. ¡Totalmente recomendada!"

Sofía M.

Cliente de Miraflores
Cliente Satisfecho 2

"El servicio de ArepaCafeLima ha cambiado mis noches. Rápido, fácil de pedir por WhatsApp y la calidad de la comida es excepcional. El programa Arepa Club es un plus genial."

Carlos G.

Cliente de San Isidro
Cliente Satisfecha 3

"Como turista, buscaba auténticos sabores venezolanos, ¡y Arepa Cafe Lima no decepcionó! El menú fue fácil de entender y la comida estuvo deliciosa. ¡Muy recomendado!"

Joe I.

Visitor from UK
Cliente satisfecha María Elena

"¡Pedí para toda mi familia y todos quedaron encantados! Las arepas llegaron perfectas, los tequeños crocantes y la atención por WhatsApp fue rapidísima. Ya somos clientes fieles. ¡Gracias ArepaCafeLima por traer este sabor tan especial a nuestra mesa!"

María Elena R.

Cliente de Surco
Cliente satisfecho Alejandro

"Como venezolano viviendo en Lima, encontrar ArepaCafeLima fue un regalo del cielo. La Arepa de Pabellón me transporta directo a Caracas. El sabor es 100% auténtico, la masa es perfecta y los ingredientes son de primera. ¡No pido en otro lado!"

Alejandro V.

Cliente de La Molina
Cliente satisfecha Daniela

"Descubrí ArepaCafeLima por recomendación de una amiga y ahora soy adicta. La Reina Pepiada es mi consentida y el delivery siempre llega antes de lo esperado. Además, ¡ya estoy acumulando puntos en el Arepa Club! La mejor inversión para mis antojos."

Daniela P.

Cliente de Barranco

#ArepaCafeLima en Instagram

Mira lo que nuestros clientes están disfrutando y comparte tus momentos con nosotros.

Arepa instagram Food spread instagram Tequeños instagram Enjoying arepa instagram Fruit juice instagram Dessert instagram Delivery instagram Arepa variety instagram Tequeños con guasacaca en Instagram Compartiendo arepas con amigos

Preguntas Frecuentes

Estamos disponibles todos los días de 7:00 a. m. a 12:00 a. m. (medianoche) para atender tus pedidos.
El tiempo estimado de entrega es de 35 a 45 minutos, dependiendo de la ubicación y del volumen de pedidos.
Aceptamos Yape, Plin, transferencia bancaria y link de pago (Visa).
Sí. Comunícate con nosotros dentro de los primeros 3 a 5 minutos después de confirmar tu pedido. Una vez iniciada la preparación, no podremos garantizar cambios.
Si tu pedido presenta algún inconveniente, contáctanos lo antes posible. Revisaremos tu caso y, según corresponda, ofreceremos un crédito o una reposición.

Tu Pedido 14

Tu carrito está vacío

¡Agrega algo delicioso del menú!

====== CART SYSTEM ==================== (function() { const CART_KEY = 'arepaCafeCart'; // Load cart from localStorage or initialize empty let cart = []; try { const saved = localStorage.getItem(CART_KEY); if (saved) cart = JSON.parse(saved); } catch(e) { cart = []; } function saveCart() { localStorage.setItem(CART_KEY, JSON.stringify(cart)); updateCartUI(); } function getItemId(name, price) { return `${name}|||${price}`; } function addToCart(name, price, image) { const id = getItemId(name, price); const existing = cart.find(item => getItemId(item.name, item.price) === id); if (existing) { existing.quantity += 1; } else { cart.push({ name, price, quantity: 1, image }); } saveCart(); openCartSidebar(); } function removeFromCart(index) { cart.splice(index, 1); saveCart(); } function updateQuantity(index, delta) { if (cart[index]) { cart[index].quantity += delta; if (cart[index].quantity <= 0) { cart.splice(index, 1); } } saveCart(); } function getTotalItems() { return cart.reduce((sum, item) => sum + item.quantity, 0); } function getSubtotal() { return cart.reduce((sum, item) => sum + (item.price * item.quantity), 0); } function updateCartUI() { const totalItems = getTotalItems(); const subtotal = getSubtotal(); // Update all cart-count badges document.querySelectorAll('.cart-count-badge').forEach(badge => { badge.textContent = totalItems; badge.style.display = totalItems > 0 ? 'flex' : 'none'; }); // Update cart sidebar items const cartItemsContainer = document.getElementById('cart-items-container'); const cartSubtotalEl = document.getElementById('cart-subtotal'); const cartTotalEl = document.getElementById('cart-total'); const cartEmptyMsg = document.getElementById('cart-empty-message'); const cartHasItems = document.getElementById('cart-has-items'); const cartFooter = document.getElementById('cart-footer-section'); if (cartItemsContainer) { if (cart.length === 0) { cartItemsContainer.innerHTML = ''; if (cartEmptyMsg) cartEmptyMsg.classList.remove('hidden'); if (cartHasItems) cartHasItems.classList.add('hidden'); if (cartFooter) cartFooter.classList.add('hidden'); } else { if (cartEmptyMsg) cartEmptyMsg.classList.add('hidden'); if (cartHasItems) cartHasItems.classList.remove('hidden'); if (cartFooter) cartFooter.classList.remove('hidden'); cartItemsContainer.innerHTML = cart.map((item, index) => `
${item.image ? `${item.name}` : ''}

${item.name}

PEN ${item.price.toFixed(2)} c/u

${item.quantity}

PEN ${(item.price * item.quantity).toFixed(2)}

`).join(''); } } if (cartSubtotalEl) cartSubtotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; if (cartTotalEl) cartTotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; } function openCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.add('open'); if (overlay) overlay.classList.add('active'); document.body.style.overflow = 'hidden'; } function closeCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.remove('open'); if (overlay) overlay.classList.remove('active'); document.body.style.overflow = ''; } // ==================== INITIALIZE ==================== function initCart() { // Create cart sidebar HTML if it doesn't exist if (!document.getElementById('cart-sidebar')) { const cartHTML = `

Tu Pedido 14

Tu carrito está vacío

¡Agrega algo delicioso del menú!

`; document.body.insertAdjacentHTML('beforeend', cartHTML); } // Create cart toggle button if it doesn't exist if (!document.getElementById('cart-toggle-btn')) { const cartToggleHTML = ` `; document.body.insertAdjacentHTML('beforeend', cartToggleHTML); } // Attach event listeners const cartToggleBtn = document.getElementById('cart-toggle-btn'); const cartCloseBtn = document.getElementById('cart-close-btn'); const cartOverlay = document.getElementById('cart-overlay'); const cartCheckoutBtn = document.getElementById('cart-checkout-btn'); if (cartToggleBtn) cartToggleBtn.addEventListener('click', openCartSidebar); if (cartCloseBtn) cartCloseBtn.addEventListener('click', closeCartSidebar); if (cartOverlay) cartOverlay.addEventListener('click', closeCartSidebar); // Delegate events for cart item buttons const cartSidebar = document.getElementById('cart-sidebar'); if (cartSidebar) { cartSidebar.addEventListener('click', function(e) { const btn = e.target.closest('button'); if (!btn) return; const action = btn.getAttribute('data-action'); const index = parseInt(btn.getAttribute('data-index')); if (isNaN(index)) return; if (action === 'increase') updateQuantity(index, 1); else if (action === 'decrease') updateQuantity(index, -1); else if (action === 'remove') removeFromCart(index); }); } // Checkout button if (cartCheckoutBtn) { cartCheckoutBtn.addEventListener('click', function() { if (cart.length === 0) return; let message = 'Hola! Quisiera hacer el siguiente pedido:%0A%0A'; cart.forEach((item, i) => { message += `${i+1}. ${item.name} x${item.quantity} - PEN ${(item.price * item.quantity).toFixed(2)}%0A`; }); message += `%0A*Total: PEN ${getSubtotal().toFixed(2)}*`; window.open(`https://wa.me/?text=${message}`, '_blank'); }); } // Connect all "Añadir" buttons document.querySelectorAll('.add-to-order-button').forEach(button => { button.addEventListener('click', function(e) { e.preventDefault(); const menuItem = this.closest('.menu-item'); if (!menuItem) return; const nameEl = menuItem.querySelector('h3'); const priceEl = menuItem.querySelector('.text-primary-red, span.text-2xl.font-bold'); const imgEl = menuItem.querySelector('img'); const name = nameEl ? nameEl.textContent.trim() : 'Producto'; const priceText = priceEl ? priceEl.textContent.trim() : 'PEN 0.00'; const price = parseFloat(priceText.replace(/[^0-9.]/g, '')); const image = imgEl ? imgEl.getAttribute('src') : ''; if (name && !isNaN(price)) { addToCart(name, price, image); // Visual feedback this.classList.add('scale-95', 'bg-yellow-600'); setTimeout(() => { this.classList.remove('scale-95', 'bg-yellow-600'); }, 200); } }); }); // Keyboard shortcut to close cart document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeCartSidebar(); }); // Initial UI update updateCartUI(); } // Run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCart); } else { initCart(); } })(); // ==================== CATEGORY FILTER ==================== document.addEventListener('DOMContentLoaded', function() { const categoryButtons = document.querySelectorAll('.category-button'); const menuItems = document.querySelectorAll('.menu-item'); function filterMenu(category) { menuItems.forEach(item => { if (category === 'all') { item.classList.remove('hidden'); } else if (item.classList.contains(`category-${category}`)) { item.classList.remove('hidden'); } else { item.classList.add('hidden'); } }); // Update active button state categoryButtons.forEach(btn => { if (btn.getAttribute('data-category') === category) { btn.classList.add('bg-primary-red', 'text-white'); btn.classList.remove('text-primary-red'); } else { btn.classList.remove('bg-primary-red', 'text-white'); btn.classList.add('text-primary-red'); } }); } categoryButtons.forEach(button => { button.addEventListener('click', () => { const category = button.getAttribute('data-category'); filterMenu(category); }); }); // Set 'all' as active by default filterMenu('all'); }); ======= ====== CART SYSTEM ==================== (function() { const CART_KEY = 'arepaCafeCart'; // Load cart from localStorage or initialize empty let cart = []; try { const saved = localStorage.getItem(CART_KEY); if (saved) cart = JSON.parse(saved); } catch(e) { cart = []; } function saveCart() { localStorage.setItem(CART_KEY, JSON.stringify(cart)); updateCartUI(); } function getItemId(name, price) { return `${name}|||${price}`; } function addToCart(name, price, image) { const id = getItemId(name, price); const existing = cart.find(item => getItemId(item.name, item.price) === id); if (existing) { existing.quantity += 1; } else { cart.push({ name, price, quantity: 1, image }); } saveCart(); openCartSidebar(); } function removeFromCart(index) { cart.splice(index, 1); saveCart(); } function updateQuantity(index, delta) { if (cart[index]) { cart[index].quantity += delta; if (cart[index].quantity <= 0) { cart.splice(index, 1); } } saveCart(); } function getTotalItems() { return cart.reduce((sum, item) => sum + item.quantity, 0); } function getSubtotal() { return cart.reduce((sum, item) => sum + (item.price * item.quantity), 0); } function updateCartUI() { const totalItems = getTotalItems(); const subtotal = getSubtotal(); // Update all cart-count badges document.querySelectorAll('.cart-count-badge').forEach(badge => { badge.textContent = totalItems; badge.style.display = totalItems > 0 ? 'flex' : 'none'; }); // Update cart sidebar items const cartItemsContainer = document.getElementById('cart-items-container'); const cartSubtotalEl = document.getElementById('cart-subtotal'); const cartTotalEl = document.getElementById('cart-total'); const cartEmptyMsg = document.getElementById('cart-empty-message'); const cartHasItems = document.getElementById('cart-has-items'); const cartFooter = document.getElementById('cart-footer-section'); if (cartItemsContainer) { if (cart.length === 0) { cartItemsContainer.innerHTML = ''; if (cartEmptyMsg) cartEmptyMsg.classList.remove('hidden'); if (cartHasItems) cartHasItems.classList.add('hidden'); if (cartFooter) cartFooter.classList.add('hidden'); } else { if (cartEmptyMsg) cartEmptyMsg.classList.add('hidden'); if (cartHasItems) cartHasItems.classList.remove('hidden'); if (cartFooter) cartFooter.classList.remove('hidden'); cartItemsContainer.innerHTML = cart.map((item, index) => `
${item.image ? `${item.name}` : ''}

${item.name}

PEN ${item.price.toFixed(2)} c/u

${item.quantity}

PEN ${(item.price * item.quantity).toFixed(2)}

`).join(''); } } if (cartSubtotalEl) cartSubtotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; if (cartTotalEl) cartTotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; } function openCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.add('open'); if (overlay) overlay.classList.add('active'); document.body.style.overflow = 'hidden'; } function closeCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.remove('open'); if (overlay) overlay.classList.remove('active'); document.body.style.overflow = ''; } // ==================== INITIALIZE ==================== function initCart() { // Create cart sidebar HTML if it doesn't exist if (!document.getElementById('cart-sidebar')) { const cartHTML = `

Tu Pedido 14

Tu carrito está vacío

¡Agrega algo delicioso del menú!

`; document.body.insertAdjacentHTML('beforeend', cartHTML); } // Create cart toggle button if it doesn't exist if (!document.getElementById('cart-toggle-btn')) { const cartToggleHTML = ` `; document.body.insertAdjacentHTML('beforeend', cartToggleHTML); } // Attach event listeners const cartToggleBtn = document.getElementById('cart-toggle-btn'); const cartCloseBtn = document.getElementById('cart-close-btn'); const cartOverlay = document.getElementById('cart-overlay'); const cartCheckoutBtn = document.getElementById('cart-checkout-btn'); if (cartToggleBtn) cartToggleBtn.addEventListener('click', openCartSidebar); if (cartCloseBtn) cartCloseBtn.addEventListener('click', closeCartSidebar); if (cartOverlay) cartOverlay.addEventListener('click', closeCartSidebar); // Delegate events for cart item buttons const cartSidebar = document.getElementById('cart-sidebar'); if (cartSidebar) { cartSidebar.addEventListener('click', function(e) { const btn = e.target.closest('button'); if (!btn) return; const action = btn.getAttribute('data-action'); const index = parseInt(btn.getAttribute('data-index')); if (isNaN(index)) return; if (action === 'increase') updateQuantity(index, 1); else if (action === 'decrease') updateQuantity(index, -1); else if (action === 'remove') removeFromCart(index); }); } // Checkout button if (cartCheckoutBtn) { cartCheckoutBtn.addEventListener('click', function() { if (cart.length === 0) return; let message = 'Hola! Quisiera hacer el siguiente pedido:%0A%0A'; cart.forEach((item, i) => { message += `${i+1}. ${item.name} x${item.quantity} - PEN ${(item.price * item.quantity).toFixed(2)}%0A`; }); message += `%0A*Total: PEN ${getSubtotal().toFixed(2)}*`; window.open(`https://wa.me/?text=${message}`, '_blank'); }); } // Connect all "Añadir" buttons document.querySelectorAll('.add-to-order-button').forEach(button => { button.addEventListener('click', function(e) { e.preventDefault(); const menuItem = this.closest('.menu-item'); if (!menuItem) return; const nameEl = menuItem.querySelector('h3'); const priceEl = menuItem.querySelector('.text-primary-red, span.text-2xl.font-bold'); const imgEl = menuItem.querySelector('img'); const name = nameEl ? nameEl.textContent.trim() : 'Producto'; const priceText = priceEl ? priceEl.textContent.trim() : 'PEN 0.00'; const price = parseFloat(priceText.replace(/[^0-9.]/g, '')); const image = imgEl ? imgEl.getAttribute('src') : ''; if (name && !isNaN(price)) { addToCart(name, price, image); // Visual feedback this.classList.add('scale-95', 'bg-yellow-600'); setTimeout(() => { this.classList.remove('scale-95', 'bg-yellow-600'); }, 200); } }); }); // Keyboard shortcut to close cart document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeCartSidebar(); }); // Initial UI update updateCartUI(); } // Run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCart); } else { initCart(); } })(); ======= // ==================== CART SYSTEM ==================== (function() { const CART_KEY = 'arepaCafeCart'; // Load cart from localStorage or initialize empty let cart = []; try { const saved = localStorage.getItem(CART_KEY); if (saved) cart = JSON.parse(saved); } catch(e) { cart = []; } function saveCart() { localStorage.setItem(CART_KEY, JSON.stringify(cart)); updateCartUI(); } function getItemId(name, price) { return `${name.trim()}|||${price}`; } function addToCart(name, price, image) { const id = getItemId(name, price); const existing = cart.find(item => getItemId(item.name, item.price) === id); if (existing) { existing.quantity += 1; } else { cart.push({ name: name.trim(), price, quantity: 1, image }); } saveCart(); openCartSidebar(); } function removeFromCart(index) { if (index >= 0 && index < cart.length) { cart.splice(index, 1); saveCart(); } } function updateQuantity(index, delta) { if (index >= 0 && index < cart.length) { cart[index].quantity += delta; if (cart[index].quantity <= 0) { cart.splice(index, 1); } saveCart(); } } function getTotalItems() { return cart.reduce((sum, item) => sum + item.quantity, 0); } function getSubtotal() { return cart.reduce((sum, item) => sum + (item.price * item.quantity), 0); } function updateCartUI() { const totalItems = getTotalItems(); const subtotal = getSubtotal(); // Update all cart-count badges const allBadges = document.querySelectorAll('.cart-count-badge'); allBadges.forEach(badge => { badge.textContent = totalItems; badge.style.display = totalItems > 0 ? 'inline-flex' : 'none'; }); // Update cart sidebar items const cartItemsContainer = document.getElementById('cart-items-container'); const cartSubtotalEl = document.getElementById('cart-subtotal'); const cartTotalEl = document.getElementById('cart-total'); const cartEmptyMsg = document.getElementById('cart-empty-message'); const cartHasItems = document.getElementById('cart-has-items'); const cartFooter = document.getElementById('cart-footer-section'); if (!cartItemsContainer) return; if (cart.length === 0) { cartItemsContainer.innerHTML = ''; if (cartEmptyMsg) cartEmptyMsg.classList.remove('hidden'); if (cartHasItems) cartHasItems.classList.add('hidden'); if (cartFooter) cartFooter.classList.add('hidden'); } else { if (cartEmptyMsg) cartEmptyMsg.classList.add('hidden'); if (cartHasItems) cartHasItems.classList.remove('hidden'); if (cartFooter) cartFooter.classList.remove('hidden'); cartItemsContainer.innerHTML = cart.map((item, index) => { const lineTotal = item.price * item.quantity; const imgTag = item.image ? `${item.name}` : `
`; return `
${imgTag}

${item.name}

PEN ${item.price.toFixed(2)} c/u

${item.quantity}

PEN ${lineTotal.toFixed(2)}

`; }).join(''); } if (cartSubtotalEl) cartSubtotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; if (cartTotalEl) cartTotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; } function openCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) { sidebar.classList.add('open'); // Ensure cart UI is refreshed when opening updateCartUI(); } if (overlay) overlay.classList.add('active'); document.body.style.overflow = 'hidden'; } function closeCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.remove('open'); if (overlay) overlay.classList.remove('active'); document.body.style.overflow = ''; } // ==================== INITIALIZE ==================== function initCart() { // Create cart sidebar HTML if it doesn't exist if (!document.getElementById('cart-sidebar')) { const cartHTML = `

Tu Pedido 14

Tu carrito está vacío

¡Agrega algo delicioso del menú!

`; document.body.insertAdjacentHTML('beforeend', cartHTML); } // Create cart toggle button if it doesn't exist if (!document.getElementById('cart-toggle-btn')) { const cartToggleHTML = ` `; document.body.insertAdjacentHTML('beforeend', cartToggleHTML); } // Attach event listeners const cartToggleBtn = document.getElementById('cart-toggle-btn'); const cartCloseBtn = document.getElementById('cart-close-btn'); const cartOverlay = document.getElementById('cart-overlay'); const cartCheckoutBtn = document.getElementById('cart-checkout-btn'); if (cartToggleBtn) cartToggleBtn.addEventListener('click', openCartSidebar); if (cartCloseBtn) cartCloseBtn.addEventListener('click', closeCartSidebar); if (cartOverlay) cartOverlay.addEventListener('click', closeCartSidebar); // Delegate events for cart item buttons const cartSidebar = document.getElementById('cart-sidebar'); if (cartSidebar) { cartSidebar.addEventListener('click', function(e) { const btn = e.target.closest('button'); if (!btn) return; const action = btn.getAttribute('data-action'); const index = parseInt(btn.getAttribute('data-index')); if (isNaN(index)) return; if (action === 'increase') updateQuantity(index, 1); else if (action === 'decrease') updateQuantity(index, -1); else if (action === 'remove') removeFromCart(index); }); } // Checkout button - open WhatsApp with order summary if (cartCheckoutBtn) { cartCheckoutBtn.addEventListener('click', function() { if (cart.length === 0) return; let message = '🍽️ *Hola! Quisiera hacer el siguiente pedido:*%0A%0A'; cart.forEach((item, i) => { const lineTotal = (item.price * item.quantity).toFixed(2); message += `*${i+1}.* ${item.name}%0A`; message += ` ${item.quantity} x PEN ${item.price.toFixed(2)} = PEN ${lineTotal}%0A%0A`; }); message += `%0A—————————————%0A`; message += `💰 *TOTAL: PEN ${getSubtotal().toFixed(2)}*%0A`; message += `📦 *Items: ${getTotalItems()}*%0A`; message += `%0A—————————————%0A`; message += `%0A¡Gracias! 🙌`; window.open(`https://wa.me/51999999999?text=${message}`, '_blank'); }); } // Connect all "Añadir" buttons function connectAddButtons() { document.querySelectorAll('.add-to-order-button').forEach(button => { // Remove existing listener by cloning (avoids duplicates on re-init) const newButton = button.cloneNode(true); button.parentNode.replaceChild(newButton, button); newButton.addEventListener('click', function(e) { e.preventDefault(); e.stopPropagation(); const menuItem = this.closest('.menu-item'); if (!menuItem) return; const nameEl = menuItem.querySelector('h3'); const imgEl = menuItem.querySelector('img'); // Find price - look for the span with text-primary-red and text-2xl font-bold const priceEl = menuItem.querySelector('span.text-primary-red.text-2xl, span.text-2xl.font-bold.text-primary-red, span.text-primary-red'); const name = nameEl ? nameEl.textContent.replace(/\s+/g, ' ').trim() : 'Producto'; const priceText = priceEl ? priceEl.textContent.replace(/\s+/g, ' ').trim() : 'PEN 0.00'; // Extract number from price text (handles PEN, S/, etc.) const priceMatch = priceText.match(/(\d+\.?\d*)/); const price = priceMatch ? parseFloat(priceMatch[1]) : 0; const image = imgEl ? imgEl.getAttribute('src') : ''; if (name && price > 0) { addToCart(name, price, image); // Visual feedback - brief pulse animation this.style.transform = 'scale(0.9)'; this.style.backgroundColor = '#eab308'; this.style.transition = 'all 0.15s ease'; setTimeout(() => { this.style.transform = 'scale(1)'; this.style.backgroundColor = ''; }, 200); } }); }); } connectAddButtons(); // Keyboard shortcut to close cart document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeCartSidebar(); }); // Initial UI update updateCartUI(); } // Run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCart); } else { initCart(); } })(); ==================== CART SYSTEM ==================== (function() { const CART_KEY = 'arepaCafeCart'; // Load cart from localStorage or initialize empty let cart = []; try { const saved = localStorage.getItem(CART_KEY); if (saved) cart = JSON.parse(saved); } catch(e) { cart = []; } function saveCart() { localStorage.setItem(CART_KEY, JSON.stringify(cart)); updateCartUI(); } function getItemId(name, price) { return `${name}|||${price}`; } function addToCart(name, price, image) { const id = getItemId(name, price); const existing = cart.find(item => getItemId(item.name, item.price) === id); if (existing) { existing.quantity += 1; } else { cart.push({ name, price, quantity: 1, image }); } saveCart(); openCartSidebar(); } function removeFromCart(index) { cart.splice(index, 1); saveCart(); } function updateQuantity(index, delta) { if (cart[index]) { cart[index].quantity += delta; if (cart[index].quantity <= 0) { cart.splice(index, 1); } } saveCart(); } function getTotalItems() { return cart.reduce((sum, item) => sum + item.quantity, 0); } function getSubtotal() { return cart.reduce((sum, item) => sum + (item.price * item.quantity), 0); } function updateCartUI() { const totalItems = getTotalItems(); const subtotal = getSubtotal(); // Update all cart-count badges document.querySelectorAll('.cart-count-badge').forEach(badge => { badge.textContent = totalItems; badge.style.display = totalItems > 0 ? 'flex' : 'none'; }); // Update cart sidebar items const cartItemsContainer = document.getElementById('cart-items-container'); const cartSubtotalEl = document.getElementById('cart-subtotal'); const cartTotalEl = document.getElementById('cart-total'); const cartEmptyMsg = document.getElementById('cart-empty-message'); const cartHasItems = document.getElementById('cart-has-items'); const cartFooter = document.getElementById('cart-footer-section'); if (cartItemsContainer) { if (cart.length === 0) { cartItemsContainer.innerHTML = ''; if (cartEmptyMsg) cartEmptyMsg.classList.remove('hidden'); if (cartHasItems) cartHasItems.classList.add('hidden'); if (cartFooter) cartFooter.classList.add('hidden'); } else { if (cartEmptyMsg) cartEmptyMsg.classList.add('hidden'); if (cartHasItems) cartHasItems.classList.remove('hidden'); if (cartFooter) cartFooter.classList.remove('hidden'); cartItemsContainer.innerHTML = cart.map((item, index) => `
${item.image ? `${item.name}` : ''}

${item.name}

PEN ${item.price.toFixed(2)} c/u

${item.quantity}

PEN ${(item.price * item.quantity).toFixed(2)}

`).join(''); } } if (cartSubtotalEl) cartSubtotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; if (cartTotalEl) cartTotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; } function openCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.add('open'); if (overlay) overlay.classList.add('active'); document.body.style.overflow = 'hidden'; } function closeCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.remove('open'); if (overlay) overlay.classList.remove('active'); document.body.style.overflow = ''; } // ==================== INITIALIZE ==================== function initCart() { // Create cart sidebar HTML if it doesn't exist if (!document.getElementById('cart-sidebar')) { const cartHTML = `

Tu Pedido 14

Tu carrito está vacío

¡Agrega algo delicioso del menú!

`; document.body.insertAdjacentHTML('beforeend', cartHTML); } // Create cart toggle button if it doesn't exist if (!document.getElementById('cart-toggle-btn')) { const cartToggleHTML = ` `; document.body.insertAdjacentHTML('beforeend', cartToggleHTML); } // Attach event listeners const cartToggleBtn = document.getElementById('cart-toggle-btn'); const cartCloseBtn = document.getElementById('cart-close-btn'); const cartOverlay = document.getElementById('cart-overlay'); const cartCheckoutBtn = document.getElementById('cart-checkout-btn'); if (cartToggleBtn) cartToggleBtn.addEventListener('click', openCartSidebar); if (cartCloseBtn) cartCloseBtn.addEventListener('click', closeCartSidebar); if (cartOverlay) cartOverlay.addEventListener('click', closeCartSidebar); // Delegate events for cart item buttons const cartSidebar = document.getElementById('cart-sidebar'); if (cartSidebar) { cartSidebar.addEventListener('click', function(e) { const btn = e.target.closest('button'); if (!btn) return; const action = btn.getAttribute('data-action'); const index = parseInt(btn.getAttribute('data-index')); if (isNaN(index)) return; if (action === 'increase') updateQuantity(index, 1); else if (action === 'decrease') updateQuantity(index, -1); else if (action === 'remove') removeFromCart(index); }); } // Checkout button if (cartCheckoutBtn) { cartCheckoutBtn.addEventListener('click', function() { if (cart.length === 0) return; let message = 'Hola! Quisiera hacer el siguiente pedido:%0A%0A'; cart.forEach((item, i) => { message += `${i+1}. ${item.name} x${item.quantity} - PEN ${(item.price * item.quantity).toFixed(2)}%0A`; }); message += `%0A*Total: PEN ${getSubtotal().toFixed(2)}*`; window.open(`https://wa.me/?text=${message}`, '_blank'); }); } // Connect all "Añadir" buttons document.querySelectorAll('.add-to-order-button').forEach(button => { button.addEventListener('click', function(e) { e.preventDefault(); const menuItem = this.closest('.menu-item'); if (!menuItem) return; const nameEl = menuItem.querySelector('h3'); const priceEl = menuItem.querySelector('.text-primary-red, span.text-2xl.font-bold'); const imgEl = menuItem.querySelector('img'); const name = nameEl ? nameEl.textContent.trim() : 'Producto'; const priceText = priceEl ? priceEl.textContent.trim() : 'PEN 0.00'; const price = parseFloat(priceText.replace(/[^0-9.]/g, '')); const image = imgEl ? imgEl.getAttribute('src') : ''; if (name && !isNaN(price)) { addToCart(name, price, image); // Visual feedback this.classList.add('scale-95', 'bg-yellow-600'); setTimeout(() => { this.classList.remove('scale-95', 'bg-yellow-600'); }, 200); } }); }); // Keyboard shortcut to close cart document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeCartSidebar(); }); // Initial UI update updateCartUI(); } // Run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCart); } else { initCart(); } })(); // ==================== CATEGORY FILTER ==================== document.addEventListener('DOMContentLoaded', function() { const categoryButtons = document.querySelectorAll('.category-button'); const menuItems = document.querySelectorAll('.menu-item'); function filterMenu(category) { menuItems.forEach(item => { if (category === 'all') { item.classList.remove('hidden'); } else if (item.classList.contains(`category-${category}`)) { item.classList.remove('hidden'); } else { item.classList.add('hidden'); } }); // Update active button state categoryButtons.forEach(btn => { if (btn.getAttribute('data-category') === category) { btn.classList.add('bg-primary-red', 'text-white'); btn.classList.remove('text-primary-red'); } else { btn.classList.remove('bg-primary-red', 'text-white'); btn.classList.add('text-primary-red'); } }); } categoryButtons.forEach(button => { button.addEventListener('click', () => { const category = button.getAttribute('data-category'); filterMenu(category); }); }); // Set 'all' as active by default filterMenu('all'); }); ======= // ==================== CART SYSTEM ==================== (function() { const CART_KEY = 'arepaCafeCart'; // Load cart from localStorage or initialize empty let cart = []; try { const saved = localStorage.getItem(CART_KEY); if (saved) cart = JSON.parse(saved); } catch(e) { cart = []; } function saveCart() { localStorage.setItem(CART_KEY, JSON.stringify(cart)); updateCartUI(); } function getItemId(name, price) { return `${name.trim()}|||${price}`; } function addToCart(name, price, image) { const id = getItemId(name, price); const existing = cart.find(item => getItemId(item.name, item.price) === id); if (existing) { existing.quantity += 1; } else { cart.push({ name: name.trim(), price, quantity: 1, image }); } saveCart(); openCartSidebar(); } function removeFromCart(index) { if (index >= 0 && index < cart.length) { cart.splice(index, 1); saveCart(); } } function updateQuantity(index, delta) { if (index >= 0 && index < cart.length) { cart[index].quantity += delta; if (cart[index].quantity <= 0) { cart.splice(index, 1); } saveCart(); } } function getTotalItems() { return cart.reduce((sum, item) => sum + item.quantity, 0); } function getSubtotal() { return cart.reduce((sum, item) => sum + (item.price * item.quantity), 0); } function updateCartUI() { const totalItems = getTotalItems(); const subtotal = getSubtotal(); // Update all cart-count badges const allBadges = document.querySelectorAll('.cart-count-badge'); allBadges.forEach(badge => { badge.textContent = totalItems; badge.style.display = totalItems > 0 ? 'inline-flex' : 'none'; }); // Update cart sidebar items const cartItemsContainer = document.getElementById('cart-items-container'); const cartSubtotalEl = document.getElementById('cart-subtotal'); const cartTotalEl = document.getElementById('cart-total'); const cartEmptyMsg = document.getElementById('cart-empty-message'); const cartHasItems = document.getElementById('cart-has-items'); const cartFooter = document.getElementById('cart-footer-section'); if (!cartItemsContainer) return; if (cart.length === 0) { cartItemsContainer.innerHTML = ''; if (cartEmptyMsg) cartEmptyMsg.classList.remove('hidden'); if (cartHasItems) cartHasItems.classList.add('hidden'); if (cartFooter) cartFooter.classList.add('hidden'); } else { if (cartEmptyMsg) cartEmptyMsg.classList.add('hidden'); if (cartHasItems) cartHasItems.classList.remove('hidden'); if (cartFooter) cartFooter.classList.remove('hidden'); cartItemsContainer.innerHTML = cart.map((item, index) => { const lineTotal = item.price * item.quantity; const imgTag = item.image ? `${item.name}` : `
`; return `
${imgTag}

${item.name}

PEN ${item.price.toFixed(2)} c/u

${item.quantity}

PEN ${lineTotal.toFixed(2)}

`; }).join(''); } if (cartSubtotalEl) cartSubtotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; if (cartTotalEl) cartTotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; } function openCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) { sidebar.classList.add('open'); // Ensure cart UI is refreshed when opening updateCartUI(); } if (overlay) overlay.classList.add('active'); document.body.style.overflow = 'hidden'; } function closeCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.remove('open'); if (overlay) overlay.classList.remove('active'); document.body.style.overflow = ''; } // ==================== INITIALIZE ==================== function initCart() { // Create cart sidebar HTML if it doesn't exist if (!document.getElementById('cart-sidebar')) { const cartHTML = `

Tu Pedido 14

Tu carrito está vacío

¡Agrega algo delicioso del menú!

`; document.body.insertAdjacentHTML('beforeend', cartHTML); } // Create cart toggle button if it doesn't exist if (!document.getElementById('cart-toggle-btn')) { const cartToggleHTML = ` `; document.body.insertAdjacentHTML('beforeend', cartToggleHTML); } // Attach event listeners const cartToggleBtn = document.getElementById('cart-toggle-btn'); const cartCloseBtn = document.getElementById('cart-close-btn'); const cartOverlay = document.getElementById('cart-overlay'); const cartCheckoutBtn = document.getElementById('cart-checkout-btn'); if (cartToggleBtn) cartToggleBtn.addEventListener('click', openCartSidebar); if (cartCloseBtn) cartCloseBtn.addEventListener('click', closeCartSidebar); if (cartOverlay) cartOverlay.addEventListener('click', closeCartSidebar); // Delegate events for cart item buttons const cartSidebar = document.getElementById('cart-sidebar'); if (cartSidebar) { cartSidebar.addEventListener('click', function(e) { const btn = e.target.closest('button'); if (!btn) return; const action = btn.getAttribute('data-action'); const index = parseInt(btn.getAttribute('data-index')); if (isNaN(index)) return; if (action === 'increase') updateQuantity(index, 1); else if (action === 'decrease') updateQuantity(index, -1); else if (action === 'remove') removeFromCart(index); }); } // Checkout button - open WhatsApp with order summary if (cartCheckoutBtn) { cartCheckoutBtn.addEventListener('click', function() { if (cart.length === 0) return; let message = '🍽️ *Hola! Quisiera hacer el siguiente pedido:*%0A%0A'; cart.forEach((item, i) => { const lineTotal = (item.price * item.quantity).toFixed(2); message += `*${i+1}.* ${item.name}%0A`; message += ` ${item.quantity} x PEN ${item.price.toFixed(2)} = PEN ${lineTotal}%0A%0A`; }); message += `%0A—————————————%0A`; message += `💰 *TOTAL: PEN ${getSubtotal().toFixed(2)}*%0A`; message += `📦 *Items: ${getTotalItems()}*%0A`; message += `%0A—————————————%0A`; message += `%0A¡Gracias! 🙌`; window.open(`https://wa.me/51999999999?text=${message}`, '_blank'); }); } // Connect all "Añadir" buttons function connectAddButtons() { document.querySelectorAll('.add-to-order-button').forEach(button => { // Remove existing listener by cloning (avoids duplicates on re-init) const newButton = button.cloneNode(true); button.parentNode.replaceChild(newButton, button); newButton.addEventListener('click', function(e) { e.preventDefault(); e.stopPropagation(); const menuItem = this.closest('.menu-item'); if (!menuItem) return; const nameEl = menuItem.querySelector('h3'); const imgEl = menuItem.querySelector('img'); // Find price - look for the span with text-primary-red and text-2xl font-bold const priceEl = menuItem.querySelector('span.text-primary-red.text-2xl, span.text-2xl.font-bold.text-primary-red, span.text-primary-red'); const name = nameEl ? nameEl.textContent.replace(/\s+/g, ' ').trim() : 'Producto'; const priceText = priceEl ? priceEl.textContent.replace(/\s+/g, ' ').trim() : 'PEN 0.00'; // Extract number from price text (handles PEN, S/, etc.) const priceMatch = priceText.match(/(\d+\.?\d*)/); const price = priceMatch ? parseFloat(priceMatch[1]) : 0; const image = imgEl ? imgEl.getAttribute('src') : ''; if (name && price > 0) { addToCart(name, price, image); // Visual feedback - brief pulse animation this.style.transform = 'scale(0.9)'; this.style.backgroundColor = '#eab308'; this.style.transition = 'all 0.15s ease'; setTimeout(() => { this.style.transform = 'scale(1)'; this.style.backgroundColor = ''; }, 200); } }); }); } connectAddButtons(); // Keyboard shortcut to close cart document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeCartSidebar(); }); // Initial UI update updateCartUI(); } // Run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCart); } else { initCart(); } })(); // ==================== CATEGORY FILTER ==================== document.addEventListener('DOMContentLoaded', function() { const categoryButtons = document.querySelectorAll('.category-button'); const menuItems = document.querySelectorAll('.menu-item'); function filterMenu(category) { menuItems.forEach(item => { if (category === 'all') { item.classList.remove('hidden'); } else if (item.classList.contains(`category-${category}`)) { item.classList.remove('hidden'); } else { item.classList.add('hidden'); } }); // Update active button state categoryButtons.forEach(btn => { if (btn.getAttribute('data-category') === category) { btn.classList.add('bg-primary-red', 'text-white'); btn.classList.remove('text-primary-red'); } else { btn.classList.remove('bg-primary-red', 'text-white'); btn.classList.add('text-primary-red'); } }); } categoryButtons.forEach(button => { button.addEventListener('click', () => { const category = button.getAttribute('data-category'); filterMenu(category); }); }); // Set 'all' as active by default filterMenu('all'); }); ====== CART SYSTEM ==================== (function() { const CART_KEY = 'arepaCafeCart'; // Load cart from localStorage or initialize empty let cart = []; try { const saved = localStorage.getItem(CART_KEY); if (saved) cart = JSON.parse(saved); } catch(e) { cart = []; } function saveCart() { localStorage.setItem(CART_KEY, JSON.stringify(cart)); updateCartUI(); } function getItemId(name, price) { return `${name}|||${price}`; } function addToCart(name, price, image) { const id = getItemId(name, price); const existing = cart.find(item => getItemId(item.name, item.price) === id); if (existing) { existing.quantity += 1; } else { cart.push({ name, price, quantity: 1, image }); } saveCart(); openCartSidebar(); } function removeFromCart(index) { cart.splice(index, 1); saveCart(); } function updateQuantity(index, delta) { if (cart[index]) { cart[index].quantity += delta; if (cart[index].quantity <= 0) { cart.splice(index, 1); } } saveCart(); } function getTotalItems() { return cart.reduce((sum, item) => sum + item.quantity, 0); } function getSubtotal() { return cart.reduce((sum, item) => sum + (item.price * item.quantity), 0); } function updateCartUI() { const totalItems = getTotalItems(); const subtotal = getSubtotal(); // Update all cart-count badges document.querySelectorAll('.cart-count-badge').forEach(badge => { badge.textContent = totalItems; badge.style.display = totalItems > 0 ? 'flex' : 'none'; }); // Update cart sidebar items const cartItemsContainer = document.getElementById('cart-items-container'); const cartSubtotalEl = document.getElementById('cart-subtotal'); const cartTotalEl = document.getElementById('cart-total'); const cartEmptyMsg = document.getElementById('cart-empty-message'); const cartHasItems = document.getElementById('cart-has-items'); const cartFooter = document.getElementById('cart-footer-section'); if (cartItemsContainer) { if (cart.length === 0) { cartItemsContainer.innerHTML = ''; if (cartEmptyMsg) cartEmptyMsg.classList.remove('hidden'); if (cartHasItems) cartHasItems.classList.add('hidden'); if (cartFooter) cartFooter.classList.add('hidden'); } else { if (cartEmptyMsg) cartEmptyMsg.classList.add('hidden'); if (cartHasItems) cartHasItems.classList.remove('hidden'); if (cartFooter) cartFooter.classList.remove('hidden'); cartItemsContainer.innerHTML = cart.map((item, index) => `
${item.image ? `${item.name}` : ''}

${item.name}

PEN ${item.price.toFixed(2)} c/u

${item.quantity}

PEN ${(item.price * item.quantity).toFixed(2)}

`).join(''); } } if (cartSubtotalEl) cartSubtotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; if (cartTotalEl) cartTotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; } function openCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.add('open'); if (overlay) overlay.classList.add('active'); document.body.style.overflow = 'hidden'; } function closeCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.remove('open'); if (overlay) overlay.classList.remove('active'); document.body.style.overflow = ''; } // ==================== INITIALIZE ==================== function initCart() { // Create cart sidebar HTML if it doesn't exist if (!document.getElementById('cart-sidebar')) { const cartHTML = `

Tu Pedido 14

Tu carrito está vacío

¡Agrega algo delicioso del menú!

`; document.body.insertAdjacentHTML('beforeend', cartHTML); } // Create cart toggle button if it doesn't exist if (!document.getElementById('cart-toggle-btn')) { const cartToggleHTML = ` `; document.body.insertAdjacentHTML('beforeend', cartToggleHTML); } // Attach event listeners const cartToggleBtn = document.getElementById('cart-toggle-btn'); const cartCloseBtn = document.getElementById('cart-close-btn'); const cartOverlay = document.getElementById('cart-overlay'); const cartCheckoutBtn = document.getElementById('cart-checkout-btn'); if (cartToggleBtn) cartToggleBtn.addEventListener('click', openCartSidebar); if (cartCloseBtn) cartCloseBtn.addEventListener('click', closeCartSidebar); if (cartOverlay) cartOverlay.addEventListener('click', closeCartSidebar); // Delegate events for cart item buttons const cartSidebar = document.getElementById('cart-sidebar'); if (cartSidebar) { cartSidebar.addEventListener('click', function(e) { const btn = e.target.closest('button'); if (!btn) return; const action = btn.getAttribute('data-action'); const index = parseInt(btn.getAttribute('data-index')); if (isNaN(index)) return; if (action === 'increase') updateQuantity(index, 1); else if (action === 'decrease') updateQuantity(index, -1); else if (action === 'remove') removeFromCart(index); }); } // Checkout button if (cartCheckoutBtn) { cartCheckoutBtn.addEventListener('click', function() { if (cart.length === 0) return; let message = 'Hola! Quisiera hacer el siguiente pedido:%0A%0A'; cart.forEach((item, i) => { message += `${i+1}. ${item.name} x${item.quantity} - PEN ${(item.price * item.quantity).toFixed(2)}%0A`; }); message += `%0A*Total: PEN ${getSubtotal().toFixed(2)}*`; window.open(`https://wa.me/?text=${message}`, '_blank'); }); } // Connect all "Añadir" buttons document.querySelectorAll('.add-to-order-button').forEach(button => { button.addEventListener('click', function(e) { e.preventDefault(); const menuItem = this.closest('.menu-item'); if (!menuItem) return; const nameEl = menuItem.querySelector('h3'); const priceEl = menuItem.querySelector('.text-primary-red, span.text-2xl.font-bold'); const imgEl = menuItem.querySelector('img'); const name = nameEl ? nameEl.textContent.trim() : 'Producto'; const priceText = priceEl ? priceEl.textContent.trim() : 'PEN 0.00'; const price = parseFloat(priceText.replace(/[^0-9.]/g, '')); const image = imgEl ? imgEl.getAttribute('src') : ''; if (name && !isNaN(price)) { addToCart(name, price, image); // Visual feedback this.classList.add('scale-95', 'bg-yellow-600'); setTimeout(() => { this.classList.remove('scale-95', 'bg-yellow-600'); }, 200); } }); }); // Keyboard shortcut to close cart document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeCartSidebar(); }); // Initial UI update updateCartUI(); } // Run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCart); } else { initCart(); } })(); ======= // ==================== CART SYSTEM ==================== (function() { const CART_KEY = 'arepaCafeCart'; // Load cart from localStorage or initialize empty let cart = []; try { const saved = localStorage.getItem(CART_KEY); if (saved) cart = JSON.parse(saved); } catch(e) { cart = []; } function saveCart() { localStorage.setItem(CART_KEY, JSON.stringify(cart)); updateCartUI(); } function getItemId(name, price) { return `${name.trim()}|||${price}`; } function addToCart(name, price, image) { const id = getItemId(name, price); const existing = cart.find(item => getItemId(item.name, item.price) === id); if (existing) { existing.quantity += 1; } else { cart.push({ name: name.trim(), price, quantity: 1, image }); } saveCart(); openCartSidebar(); } function removeFromCart(index) { if (index >= 0 && index < cart.length) { cart.splice(index, 1); saveCart(); } } function updateQuantity(index, delta) { if (index >= 0 && index < cart.length) { cart[index].quantity += delta; if (cart[index].quantity <= 0) { cart.splice(index, 1); } saveCart(); } } function getTotalItems() { return cart.reduce((sum, item) => sum + item.quantity, 0); } function getSubtotal() { return cart.reduce((sum, item) => sum + (item.price * item.quantity), 0); } function updateCartUI() { const totalItems = getTotalItems(); const subtotal = getSubtotal(); // Update all cart-count badges const allBadges = document.querySelectorAll('.cart-count-badge'); allBadges.forEach(badge => { badge.textContent = totalItems; badge.style.display = totalItems > 0 ? 'inline-flex' : 'none'; }); // Update cart sidebar items const cartItemsContainer = document.getElementById('cart-items-container'); const cartSubtotalEl = document.getElementById('cart-subtotal'); const cartTotalEl = document.getElementById('cart-total'); const cartEmptyMsg = document.getElementById('cart-empty-message'); const cartHasItems = document.getElementById('cart-has-items'); const cartFooter = document.getElementById('cart-footer-section'); if (!cartItemsContainer) return; if (cart.length === 0) { cartItemsContainer.innerHTML = ''; if (cartEmptyMsg) cartEmptyMsg.classList.remove('hidden'); if (cartHasItems) cartHasItems.classList.add('hidden'); if (cartFooter) cartFooter.classList.add('hidden'); } else { if (cartEmptyMsg) cartEmptyMsg.classList.add('hidden'); if (cartHasItems) cartHasItems.classList.remove('hidden'); if (cartFooter) cartFooter.classList.remove('hidden'); cartItemsContainer.innerHTML = cart.map((item, index) => { const lineTotal = item.price * item.quantity; const imgTag = item.image ? `` : `
`; return `
${imgTag}

${item.name}

PEN ${item.price.toFixed(2)} c/u

${item.quantity}

PEN ${lineTotal.toFixed(2)}

`; }).join(''); } if (cartSubtotalEl) cartSubtotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; if (cartTotalEl) cartTotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; } function openCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) { sidebar.classList.add('open'); // Ensure cart UI is refreshed when opening updateCartUI(); } if (overlay) overlay.classList.add('active'); document.body.style.overflow = 'hidden'; } function closeCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.remove('open'); if (overlay) overlay.classList.remove('active'); document.body.style.overflow = ''; } // ==================== INITIALIZE ==================== function initCart() { // Create cart sidebar HTML if it doesn't exist if (!document.getElementById('cart-sidebar')) { const cartHTML = `

Tu Pedido 14

Tu carrito está vacío

¡Agrega algo delicioso del menú!

`; document.body.insertAdjacentHTML('beforeend', cartHTML); } // Create cart toggle button if it doesn't exist if (!document.getElementById('cart-toggle-btn')) { const cartToggleHTML = ` `; document.body.insertAdjacentHTML('beforeend', cartToggleHTML); } // Attach event listeners const cartToggleBtn = document.getElementById('cart-toggle-btn'); const cartCloseBtn = document.getElementById('cart-close-btn'); const cartOverlay = document.getElementById('cart-overlay'); const cartCheckoutBtn = document.getElementById('cart-checkout-btn'); if (cartToggleBtn) cartToggleBtn.addEventListener('click', openCartSidebar); if (cartCloseBtn) cartCloseBtn.addEventListener('click', closeCartSidebar); if (cartOverlay) cartOverlay.addEventListener('click', closeCartSidebar); // Delegate events for cart item buttons const cartSidebar = document.getElementById('cart-sidebar'); if (cartSidebar) { cartSidebar.addEventListener('click', function(e) { const btn = e.target.closest('button'); if (!btn) return; const action = btn.getAttribute('data-action'); const index = parseInt(btn.getAttribute('data-index')); if (isNaN(index)) return; if (action === 'increase') updateQuantity(index, 1); else if (action === 'decrease') updateQuantity(index, -1); else if (action === 'remove') removeFromCart(index); }); } // Checkout button - open WhatsApp with order summary if (cartCheckoutBtn) { cartCheckoutBtn.addEventListener('click', function() { if (cart.length === 0) return; let message = '🍽️ *Hola! Quisiera hacer el siguiente pedido:*%0A%0A'; cart.forEach((item, i) => { const lineTotal = (item.price * item.quantity).toFixed(2); message += `*${i+1}.* ${item.name}%0A`; message += ` ${item.quantity} x PEN ${item.price.toFixed(2)} = PEN ${lineTotal}%0A%0A`; }); message += `%0A—————————————%0A`; message += `💰 *TOTAL: PEN ${getSubtotal().toFixed(2)}*%0A`; message += `📦 *Items: ${getTotalItems()}*%0A`; message += `%0A—————————————%0A`; message += `%0A¡Gracias! 🙌`; window.open(`https://wa.me/51999999999?text=${message}`, '_blank'); }); } // Connect all "Añadir" buttons function connectAddButtons() { document.querySelectorAll('.add-to-order-button').forEach(button => { // Remove existing listener by cloning (avoids duplicates on re-init) const newButton = button.cloneNode(true); button.parentNode.replaceChild(newButton, button); newButton.addEventListener('click', function(e) { e.preventDefault(); e.stopPropagation(); const menuItem = this.closest('.menu-item'); if (!menuItem) return; const nameEl = menuItem.querySelector('h3'); const imgEl = menuItem.querySelector('img'); // Find price - look for the span with text-primary-red and text-2xl font-bold const priceEl = menuItem.querySelector('span.text-primary-red.text-2xl, span.text-2xl.font-bold.text-primary-red, span.text-primary-red'); const name = nameEl ? nameEl.textContent.replace(/\s+/g, ' ').trim() : 'Producto'; const priceText = priceEl ? priceEl.textContent.replace(/\s+/g, ' ').trim() : 'PEN 0.00'; // Extract number from price text (handles PEN, S/, etc.) const priceMatch = priceText.match(/(\d+\.?\d*)/); const price = priceMatch ? parseFloat(priceMatch[1]) : 0; const image = imgEl ? imgEl.getAttribute('src') : ''; if (name && price > 0) { addToCart(name, price, image); // Visual feedback - brief pulse animation this.style.transform = 'scale(0.9)'; this.style.backgroundColor = '#eab308'; this.style.transition = 'all 0.15s ease'; setTimeout(() => { this.style.transform = 'scale(1)'; this.style.backgroundColor = ''; }, 200); } }); }); } connectAddButtons(); // Keyboard shortcut to close cart document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeCartSidebar(); }); // Initial UI update updateCartUI(); } // Run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCart); } else { initCart(); } })(); ==================== CART SYSTEM ==================== (function() { const CART_KEY = 'arepaCafeCart'; // Load cart from localStorage or initialize empty let cart = []; try { const saved = localStorage.getItem(CART_KEY); if (saved) cart = JSON.parse(saved); } catch(e) { cart = []; } function saveCart() { localStorage.setItem(CART_KEY, JSON.stringify(cart)); updateCartUI(); } function getItemId(name, price) { return `${name}|||${price}`; } function addToCart(name, price, image) { const id = getItemId(name, price); const existing = cart.find(item => getItemId(item.name, item.price) === id); if (existing) { existing.quantity += 1; } else { cart.push({ name, price, quantity: 1, image }); } saveCart(); openCartSidebar(); } function removeFromCart(index) { cart.splice(index, 1); saveCart(); } function updateQuantity(index, delta) { if (cart[index]) { cart[index].quantity += delta; if (cart[index].quantity <= 0) { cart.splice(index, 1); } } saveCart(); } function getTotalItems() { return cart.reduce((sum, item) => sum + item.quantity, 0); } function getSubtotal() { return cart.reduce((sum, item) => sum + (item.price * item.quantity), 0); } function updateCartUI() { const totalItems = getTotalItems(); const subtotal = getSubtotal(); // Update all cart-count badges document.querySelectorAll('.cart-count-badge').forEach(badge => { badge.textContent = totalItems; badge.style.display = totalItems > 0 ? 'flex' : 'none'; }); // Update cart sidebar items const cartItemsContainer = document.getElementById('cart-items-container'); const cartSubtotalEl = document.getElementById('cart-subtotal'); const cartTotalEl = document.getElementById('cart-total'); const cartEmptyMsg = document.getElementById('cart-empty-message'); const cartHasItems = document.getElementById('cart-has-items'); const cartFooter = document.getElementById('cart-footer-section'); if (cartItemsContainer) { if (cart.length === 0) { cartItemsContainer.innerHTML = ''; if (cartEmptyMsg) cartEmptyMsg.classList.remove('hidden'); if (cartHasItems) cartHasItems.classList.add('hidden'); if (cartFooter) cartFooter.classList.add('hidden'); } else { if (cartEmptyMsg) cartEmptyMsg.classList.add('hidden'); if (cartHasItems) cartHasItems.classList.remove('hidden'); if (cartFooter) cartFooter.classList.remove('hidden'); cartItemsContainer.innerHTML = cart.map((item, index) => `
${item.image ? `${item.name}` : ''}

${item.name}

PEN ${item.price.toFixed(2)} c/u

${item.quantity}

PEN ${(item.price * item.quantity).toFixed(2)}

`).join(''); } } if (cartSubtotalEl) cartSubtotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; if (cartTotalEl) cartTotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; } function openCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.add('open'); if (overlay) overlay.classList.add('active'); document.body.style.overflow = 'hidden'; } function closeCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.remove('open'); if (overlay) overlay.classList.remove('active'); document.body.style.overflow = ''; } // ==================== INITIALIZE ==================== function initCart() { // Create cart sidebar HTML if it doesn't exist if (!document.getElementById('cart-sidebar')) { const cartHTML = `

Tu Pedido 14

Tu carrito está vacío

¡Agrega algo delicioso del menú!

`; document.body.insertAdjacentHTML('beforeend', cartHTML); } // Create cart toggle button if it doesn't exist if (!document.getElementById('cart-toggle-btn')) { const cartToggleHTML = ` `; document.body.insertAdjacentHTML('beforeend', cartToggleHTML); } // Attach event listeners const cartToggleBtn = document.getElementById('cart-toggle-btn'); const cartCloseBtn = document.getElementById('cart-close-btn'); const cartOverlay = document.getElementById('cart-overlay'); const cartCheckoutBtn = document.getElementById('cart-checkout-btn'); if (cartToggleBtn) cartToggleBtn.addEventListener('click', openCartSidebar); if (cartCloseBtn) cartCloseBtn.addEventListener('click', closeCartSidebar); if (cartOverlay) cartOverlay.addEventListener('click', closeCartSidebar); // Delegate events for cart item buttons const cartSidebar = document.getElementById('cart-sidebar'); if (cartSidebar) { cartSidebar.addEventListener('click', function(e) { const btn = e.target.closest('button'); if (!btn) return; const action = btn.getAttribute('data-action'); const index = parseInt(btn.getAttribute('data-index')); if (isNaN(index)) return; if (action === 'increase') updateQuantity(index, 1); else if (action === 'decrease') updateQuantity(index, -1); else if (action === 'remove') removeFromCart(index); }); } // Checkout button if (cartCheckoutBtn) { cartCheckoutBtn.addEventListener('click', function() { if (cart.length === 0) return; let message = 'Hola! Quisiera hacer el siguiente pedido:%0A%0A'; cart.forEach((item, i) => { message += `${i+1}. ${item.name} x${item.quantity} - PEN ${(item.price * item.quantity).toFixed(2)}%0A`; }); message += `%0A*Total: PEN ${getSubtotal().toFixed(2)}*`; window.open(`https://wa.me/?text=${message}`, '_blank'); }); } // Connect all "Añadir" buttons document.querySelectorAll('.add-to-order-button').forEach(button => { button.addEventListener('click', function(e) { e.preventDefault(); const menuItem = this.closest('.menu-item'); if (!menuItem) return; const nameEl = menuItem.querySelector('h3'); const priceEl = menuItem.querySelector('.text-primary-red, span.text-2xl.font-bold'); const imgEl = menuItem.querySelector('img'); const name = nameEl ? nameEl.textContent.trim() : 'Producto'; const priceText = priceEl ? priceEl.textContent.trim() : 'PEN 0.00'; const price = parseFloat(priceText.replace(/[^0-9.]/g, '')); const image = imgEl ? imgEl.getAttribute('src') : ''; if (name && !isNaN(price)) { addToCart(name, price, image); // Visual feedback this.classList.add('scale-95', 'bg-yellow-600'); setTimeout(() => { this.classList.remove('scale-95', 'bg-yellow-600'); }, 200); } }); }); // Keyboard shortcut to close cart document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeCartSidebar(); }); // Initial UI update updateCartUI(); } // Run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCart); } else { initCart(); } })(); // ==================== CATEGORY FILTER ==================== document.addEventListener('DOMContentLoaded', function() { const categoryButtons = document.querySelectorAll('.category-button'); const menuItems = document.querySelectorAll('.menu-item'); function filterMenu(category) { menuItems.forEach(item => { if (category === 'all') { item.classList.remove('hidden'); } else if (item.classList.contains(`category-${category}`)) { item.classList.remove('hidden'); } else { item.classList.add('hidden'); } }); // Update active button state categoryButtons.forEach(btn => { if (btn.getAttribute('data-category') === category) { btn.classList.add('bg-primary-red', 'text-white'); btn.classList.remove('text-primary-red'); } else { btn.classList.remove('bg-primary-red', 'text-white'); btn.classList.add('text-primary-red'); } }); } categoryButtons.forEach(button => { button.addEventListener('click', () => { const category = button.getAttribute('data-category'); filterMenu(category); }); }); // Set 'all' as active by default filterMenu('all'); }); ======= ====== CART SYSTEM ==================== (function() { const CART_KEY = 'arepaCafeCart'; // Load cart from localStorage or initialize empty let cart = []; try { const saved = localStorage.getItem(CART_KEY); if (saved) cart = JSON.parse(saved); } catch(e) { cart = []; } function saveCart() { localStorage.setItem(CART_KEY, JSON.stringify(cart)); updateCartUI(); } function getItemId(name, price) { return `${name}|||${price}`; } function addToCart(name, price, image) { const id = getItemId(name, price); const existing = cart.find(item => getItemId(item.name, item.price) === id); if (existing) { existing.quantity += 1; } else { cart.push({ name, price, quantity: 1, image }); } saveCart(); openCartSidebar(); } function removeFromCart(index) { cart.splice(index, 1); saveCart(); } function updateQuantity(index, delta) { if (cart[index]) { cart[index].quantity += delta; if (cart[index].quantity <= 0) { cart.splice(index, 1); } } saveCart(); } function getTotalItems() { return cart.reduce((sum, item) => sum + item.quantity, 0); } function getSubtotal() { return cart.reduce((sum, item) => sum + (item.price * item.quantity), 0); } function updateCartUI() { const totalItems = getTotalItems(); const subtotal = getSubtotal(); // Update all cart-count badges document.querySelectorAll('.cart-count-badge').forEach(badge => { badge.textContent = totalItems; badge.style.display = totalItems > 0 ? 'flex' : 'none'; }); // Update cart sidebar items const cartItemsContainer = document.getElementById('cart-items-container'); const cartSubtotalEl = document.getElementById('cart-subtotal'); const cartTotalEl = document.getElementById('cart-total'); const cartEmptyMsg = document.getElementById('cart-empty-message'); const cartHasItems = document.getElementById('cart-has-items'); const cartFooter = document.getElementById('cart-footer-section'); if (cartItemsContainer) { if (cart.length === 0) { cartItemsContainer.innerHTML = ''; if (cartEmptyMsg) cartEmptyMsg.classList.remove('hidden'); if (cartHasItems) cartHasItems.classList.add('hidden'); if (cartFooter) cartFooter.classList.add('hidden'); } else { if (cartEmptyMsg) cartEmptyMsg.classList.add('hidden'); if (cartHasItems) cartHasItems.classList.remove('hidden'); if (cartFooter) cartFooter.classList.remove('hidden'); cartItemsContainer.innerHTML = cart.map((item, index) => `
${item.image ? `${item.name}` : ''}

${item.name}

PEN ${item.price.toFixed(2)} c/u

${item.quantity}

PEN ${(item.price * item.quantity).toFixed(2)}

`).join(''); } } if (cartSubtotalEl) cartSubtotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; if (cartTotalEl) cartTotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; } function openCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.add('open'); if (overlay) overlay.classList.add('active'); document.body.style.overflow = 'hidden'; } function closeCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.remove('open'); if (overlay) overlay.classList.remove('active'); document.body.style.overflow = ''; } // ==================== INITIALIZE ==================== function initCart() { // Create cart sidebar HTML if it doesn't exist if (!document.getElementById('cart-sidebar')) { const cartHTML = `

Tu Pedido 14

`; document.body.insertAdjacentHTML('beforeend', cartHTML); } // Create cart toggle button if it doesn't exist if (!document.getElementById('cart-toggle-btn')) { const cartToggleHTML = ` `; document.body.insertAdjacentHTML('beforeend', cartToggleHTML); } // Attach event listeners const cartToggleBtn = document.getElementById('cart-toggle-btn'); const cartCloseBtn = document.getElementById('cart-close-btn'); const cartOverlay = document.getElementById('cart-overlay'); const cartCheckoutBtn = document.getElementById('cart-checkout-btn'); if (cartToggleBtn) cartToggleBtn.addEventListener('click', openCartSidebar); if (cartCloseBtn) cartCloseBtn.addEventListener('click', closeCartSidebar); if (cartOverlay) cartOverlay.addEventListener('click', closeCartSidebar); // Delegate events for cart item buttons const cartSidebar = document.getElementById('cart-sidebar'); if (cartSidebar) { cartSidebar.addEventListener('click', function(e) { const btn = e.target.closest('button'); if (!btn) return; const action = btn.getAttribute('data-action'); const index = parseInt(btn.getAttribute('data-index')); if (isNaN(index)) return; if (action === 'increase') updateQuantity(index, 1); else if (action === 'decrease') updateQuantity(index, -1); else if (action === 'remove') removeFromCart(index); }); } // Checkout button if (cartCheckoutBtn) { cartCheckoutBtn.addEventListener('click', function() { if (cart.length === 0) return; let message = 'Hola! Quisiera hacer el siguiente pedido:%0A%0A'; cart.forEach((item, i) => { message += `${i+1}. ${item.name} x${item.quantity} - PEN ${(item.price * item.quantity).toFixed(2)}%0A`; }); message += `%0A*Total: PEN ${getSubtotal().toFixed(2)}*`; window.open(`https://wa.me/?text=${message}`, '_blank'); }); } // Connect all "Añadir" buttons document.querySelectorAll('.add-to-order-button').forEach(button => { button.addEventListener('click', function(e) { e.preventDefault(); const menuItem = this.closest('.menu-item'); if (!menuItem) return; const nameEl = menuItem.querySelector('h3'); const priceEl = menuItem.querySelector('.text-primary-red, span.text-2xl.font-bold'); const imgEl = menuItem.querySelector('img'); const name = nameEl ? nameEl.textContent.trim() : 'Producto'; const priceText = priceEl ? priceEl.textContent.trim() : 'PEN 0.00'; const price = parseFloat(priceText.replace(/[^0-9.]/g, '')); const image = imgEl ? imgEl.getAttribute('src') : ''; if (name && !isNaN(price)) { addToCart(name, price, image); // Visual feedback this.classList.add('scale-95', 'bg-yellow-600'); setTimeout(() => { this.classList.remove('scale-95', 'bg-yellow-600'); }, 200); } }); }); // Keyboard shortcut to close cart document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeCartSidebar(); }); // Initial UI update updateCartUI(); } // Run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCart); } else { initCart(); } })(); ======= // ==================== CART SYSTEM ==================== (function() { const CART_KEY = 'arepaCafeCart'; // Load cart from localStorage or initialize empty let cart = []; try { const saved = localStorage.getItem(CART_KEY); if (saved) cart = JSON.parse(saved); } catch(e) { cart = []; } function saveCart() { localStorage.setItem(CART_KEY, JSON.stringify(cart)); updateCartUI(); } function getItemId(name, price) { return `${name}|||${price}`; } function addToCart(name, price, image) { const id = getItemId(name, price); const existing = cart.find(item => getItemId(item.name, item.price) === id); if (existing) { existing.quantity += 1; } else { cart.push({ name, price, quantity: 1, image }); } saveCart(); openCartSidebar(); } function removeFromCart(index) { cart.splice(index, 1); saveCart(); } function updateQuantity(index, delta) { if (cart[index]) { cart[index].quantity += delta; if (cart[index].quantity <= 0) { cart.splice(index, 1); } } saveCart(); } function getTotalItems() { return cart.reduce((sum, item) => sum + item.quantity, 0); } function getSubtotal() { return cart.reduce((sum, item) => sum + (item.price * item.quantity), 0); } function updateCartUI() { const totalItems = getTotalItems(); const subtotal = getSubtotal(); // Update all cart-count badges document.querySelectorAll('.cart-count-badge').forEach(badge => { badge.textContent = totalItems; badge.style.display = totalItems > 0 ? 'flex' : 'none'; }); // Update cart sidebar items const cartItemsContainer = document.getElementById('cart-items-container'); const cartSubtotalEl = document.getElementById('cart-subtotal'); const cartTotalEl = document.getElementById('cart-total'); const cartEmptyMsg = document.getElementById('cart-empty-message'); const cartHasItems = document.getElementById('cart-has-items'); const cartFooter = document.getElementById('cart-footer-section'); if (cartItemsContainer) { if (cart.length === 0) { cartItemsContainer.innerHTML = ''; if (cartEmptyMsg) cartEmptyMsg.classList.remove('hidden'); if (cartHasItems) cartHasItems.classList.add('hidden'); if (cartFooter) cartFooter.classList.add('hidden'); } else { if (cartEmptyMsg) cartEmptyMsg.classList.add('hidden'); if (cartHasItems) cartHasItems.classList.remove('hidden'); if (cartFooter) cartFooter.classList.remove('hidden'); cartItemsContainer.innerHTML = cart.map((item, index) => `
${item.image ? `${item.name}` : ''}

${item.name}

PEN ${item.price.toFixed(2)} c/u

${item.quantity}

PEN ${(item.price * item.quantity).toFixed(2)}

`).join(''); } } if (cartSubtotalEl) cartSubtotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; if (cartTotalEl) cartTotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; } function openCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.add('open'); if (overlay) overlay.classList.add('active'); document.body.style.overflow = 'hidden'; } function closeCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.remove('open'); if (overlay) overlay.classList.remove('active'); document.body.style.overflow = ''; } // ==================== INITIALIZE ==================== function initCart() { // Create cart sidebar HTML if it doesn't exist if (!document.getElementById('cart-sidebar')) { const cartHTML = `

Tu Pedido 14

Tu carrito está vacío

¡Agrega algo delicioso del menú!

`; document.body.insertAdjacentHTML('beforeend', cartHTML); } // Create cart toggle button if it doesn't exist if (!document.getElementById('cart-toggle-btn')) { const cartToggleHTML = ` `; document.body.insertAdjacentHTML('beforeend', cartToggleHTML); } // Attach event listeners const cartToggleBtn = document.getElementById('cart-toggle-btn'); const cartCloseBtn = document.getElementById('cart-close-btn'); const cartOverlay = document.getElementById('cart-overlay'); const cartCheckoutBtn = document.getElementById('cart-checkout-btn'); if (cartToggleBtn) cartToggleBtn.addEventListener('click', openCartSidebar); if (cartCloseBtn) cartCloseBtn.addEventListener('click', closeCartSidebar); if (cartOverlay) cartOverlay.addEventListener('click', closeCartSidebar); // Delegate events for cart item buttons const cartSidebar = document.getElementById('cart-sidebar'); if (cartSidebar) { cartSidebar.addEventListener('click', function(e) { const btn = e.target.closest('button'); if (!btn) return; const action = btn.getAttribute('data-action'); const index = parseInt(btn.getAttribute('data-index')); if (isNaN(index)) return; if (action === 'increase') updateQuantity(index, 1); else if (action === 'decrease') updateQuantity(index, -1); else if (action === 'remove') removeFromCart(index); }); } // Checkout button if (cartCheckoutBtn) { cartCheckoutBtn.addEventListener('click', function() { if (cart.length === 0) return; let message = 'Hola! Quisiera hacer el siguiente pedido:%0A%0A'; cart.forEach((item, i) => { message += `${i+1}. ${item.name} x${item.quantity} - PEN ${(item.price * item.quantity).toFixed(2)}%0A`; }); message += `%0A*Total: PEN ${getSubtotal().toFixed(2)}*`; window.open(`https://wa.me/?text=${message}`, '_blank'); }); } // Connect all "Añadir" buttons document.querySelectorAll('.add-to-order-button').forEach(button => { button.addEventListener('click', function(e) { e.preventDefault(); const menuItem = this.closest('.menu-item'); if (!menuItem) return; const nameEl = menuItem.querySelector('h3'); const priceEl = menuItem.querySelector('.text-primary-red, span.text-2xl.font-bold'); const imgEl = menuItem.querySelector('img'); const name = nameEl ? nameEl.textContent.trim() : 'Producto'; const priceText = priceEl ? priceEl.textContent.trim() : 'PEN 0.00'; const price = parseFloat(priceText.replace(/[^0-9.]/g, '')); const image = imgEl ? imgEl.getAttribute('src') : ''; if (name && !isNaN(price)) { addToCart(name, price, image); // Visual feedback this.classList.add('scale-95', 'bg-yellow-600'); setTimeout(() => { this.classList.remove('scale-95', 'bg-yellow-600'); }, 200); } }); }); // Keyboard shortcut to close cart document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeCartSidebar(); }); // Initial UI update updateCartUI(); } // Run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCart); } else { initCart(); } })(); // ==================== CATEGORY FILTER ==================== document.addEventListener('DOMContentLoaded', function() { const categoryButtons = document.querySelectorAll('.category-button'); const menuItems = document.querySelectorAll('.menu-item'); function filterMenu(category) { menuItems.forEach(item => { if (category === 'all') { item.classList.remove('hidden'); } else if (item.classList.contains(`category-${category}`)) { item.classList.remove('hidden'); } else { item.classList.add('hidden'); } }); // Update active button state categoryButtons.forEach(btn => { if (btn.getAttribute('data-category') === category) { btn.classList.add('bg-primary-red', 'text-white'); btn.classList.remove('text-primary-red'); } else { btn.classList.remove('bg-primary-red', 'text-white'); btn.classList.add('text-primary-red'); } }); } categoryButtons.forEach(button => { button.addEventListener('click', () => { const category = button.getAttribute('data-category'); filterMenu(category); }); }); // Set 'all' as active by default filterMenu('all'); }); ======= // ==================== CART SYSTEM + CATEGORY FILTER ==================== (function() { const CART_KEY = 'arepaCafeCart'; let cart = []; try { const saved = localStorage.getItem(CART_KEY); if (saved) cart = JSON.parse(saved); } catch(e) { cart = []; } function saveCart() { localStorage.setItem(CART_KEY, JSON.stringify(cart)); updateCartUI(); } function getItemId(name, price) { return `${name.trim()}|||${price}`; } function addToCart(name, price, image) { const id = getItemId(name, price); const existing = cart.find(item => getItemId(item.name, item.price) === id); if (existing) { existing.quantity += 1; } else { cart.push({ name: name.trim(), price, quantity: 1, image }); } saveCart(); openCartSidebar(); } function removeFromCart(index) { if (index >= 0 && index < cart.length) { cart.splice(index, 1); saveCart(); } } function updateQuantity(index, delta) { if (index >= 0 && index < cart.length) { cart[index].quantity += delta; if (cart[index].quantity <= 0) { cart.splice(index, 1); } saveCart(); } } function getTotalItems() { return cart.reduce((sum, item) => sum + item.quantity, 0); } function getSubtotal() { return cart.reduce((sum, item) => sum + (item.price * item.quantity), 0); } function updateCartUI() { const totalItems = getTotalItems(); const subtotal = getSubtotal(); const allBadges = document.querySelectorAll('.cart-count-badge'); allBadges.forEach(badge => { badge.textContent = totalItems; badge.style.display = totalItems > 0 ? 'inline-flex' : 'none'; }); const cartItemsContainer = document.getElementById('cart-items-container'); const cartSubtotalEl = document.getElementById('cart-subtotal'); const cartTotalEl = document.getElementById('cart-total'); const cartEmptyMsg = document.getElementById('cart-empty-message'); const cartHasItems = document.getElementById('cart-has-items'); const cartFooter = document.getElementById('cart-footer-section'); if (!cartItemsContainer) return; if (cart.length === 0) { cartItemsContainer.innerHTML = ''; if (cartEmptyMsg) cartEmptyMsg.classList.remove('hidden'); if (cartHasItems) cartHasItems.classList.add('hidden'); if (cartFooter) cartFooter.classList.add('hidden'); } else { if (cartEmptyMsg) cartEmptyMsg.classList.add('hidden'); if (cartHasItems) cartHasItems.classList.remove('hidden'); if (cartFooter) cartFooter.classList.remove('hidden'); cartItemsContainer.innerHTML = cart.map((item, index) => { const lineTotal = item.price * item.quantity; return `
${item.image ? `${item.name}` : ''}

${item.name}

PEN ${item.price.toFixed(2)} c/u

${item.quantity}

PEN ${lineTotal.toFixed(2)}

`; }).join(''); } if (cartSubtotalEl) cartSubtotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; if (cartTotalEl) cartTotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; } function openCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.add('open'); if (overlay) overlay.classList.add('active'); document.body.style.overflow = 'hidden'; } function closeCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.remove('open'); if (overlay) overlay.classList.remove('active'); document.body.style.overflow = ''; } function initCart() { if (!document.getElementById('cart-sidebar')) { const cartHTML = `

Tu Carrito 14

Tu carrito está vacío

¡Agrega algo delicioso del menú!

`; document.body.insertAdjacentHTML('beforeend', cartHTML); } if (!document.getElementById('cart-toggle-btn')) { const cartToggleHTML = ` `; document.body.insertAdjacentHTML('beforeend', cartToggleHTML); } const cartToggleBtn = document.getElementById('cart-toggle-btn'); const cartCloseBtn = document.getElementById('cart-close-btn'); const cartOverlay = document.getElementById('cart-overlay'); const cartCheckoutBtn = document.getElementById('cart-checkout-btn'); if (cartToggleBtn) cartToggleBtn.addEventListener('click', openCartSidebar); if (cartCloseBtn) cartCloseBtn.addEventListener('click', closeCartSidebar); if (cartOverlay) cartOverlay.addEventListener('click', closeCartSidebar); const cartSidebar = document.getElementById('cart-sidebar'); if (cartSidebar) { cartSidebar.addEventListener('click', function(e) { const btn = e.target.closest('button'); if (!btn) return; const action = btn.getAttribute('data-action'); const index = parseInt(btn.getAttribute('data-index')); if (isNaN(index)) return; if (action === 'increase') updateQuantity(index, 1); else if (action === 'decrease') updateQuantity(index, -1); else if (action === 'remove') removeFromCart(index); }); } if (cartCheckoutBtn) { cartCheckoutBtn.addEventListener('click', function() { if (cart.length === 0) return; let message = 'Hola! Quisiera hacer el siguiente pedido:%0A%0A'; cart.forEach((item, i) => { const lineTotal = (item.price * item.quantity).toFixed(2); message += `${i+1}. ${item.name} x${item.quantity} - PEN ${lineTotal}%0A`; }); message += `%0A*Total: PEN ${getSubtotal().toFixed(2)}*`; window.open(`https://wa.me/?text=${message}`, '_blank'); }); } // Connect all "Añadir" buttons (using a single, clean listener) document.querySelectorAll('.add-to-order-button').forEach(button => { button.addEventListener('click', function(e) { e.preventDefault(); const menuItem = this.closest('.menu-item'); if (!menuItem) return; const nameEl = menuItem.querySelector('h3'); const imgEl = menuItem.querySelector('img'); // Find the price span specifically (the one inside the flex container that holds the button) const priceEl = menuItem.querySelector('.flex.items-center.justify-between span.text-primary-red.text-2xl.font-bold'); const name = nameEl ? nameEl.textContent.replace(/\s+/g, ' ').trim() : 'Producto'; const priceText = priceEl ? priceEl.textContent.replace(/\s+/g, ' ').trim() : 'PEN 0.00'; const priceMatch = priceText.match(/(\d+\.?\d*)/); const price = priceMatch ? parseFloat(priceMatch[1]) : 0; const image = imgEl ? imgEl.getAttribute('src') : ''; if (name && price > 0) { addToCart(name, price, image); // Visual feedback this.style.transform = 'scale(0.9)'; this.style.backgroundColor = '#eab308'; this.style.transition = 'all 0.15s ease'; setTimeout(() => { this.style.transform = ''; this.style.backgroundColor = ''; }, 200); } }); }); document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeCartSidebar(); }); updateCartUI(); } // Run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCart); } else { initCart(); } // Category filter document.addEventListener('DOMContentLoaded', function() { const categoryButtons = document.querySelectorAll('.category-button'); const menuItems = document.querySelectorAll('.menu-item'); function filterMenu(category) { menuItems.forEach(item => { if (category === 'all') { item.classList.remove('hidden'); } else if (item.classList.contains(`category-${category}`)) { item.classList.remove('hidden'); } else { item.classList.add('hidden'); } }); categoryButtons.forEach(btn => { if (btn.getAttribute('data-category') === category) { btn.classList.add('bg-primary-red', 'text-white'); btn.classList.remove('text-primary-red'); } else { btn.classList.remove('bg-primary-red', 'text-white'); btn.classList.add('text-primary-red'); } }); } categoryButtons.forEach(button => { button.addEventListener('click', () => { const category = button.getAttribute('data-category'); filterMenu(category); }); }); filterMenu('all'); }); })(); ====== CART SYSTEM ==================== (function() { const CART_KEY = 'arepaCafeCart'; // Load cart from localStorage or initialize empty let cart = []; try { const saved = localStorage.getItem(CART_KEY); if (saved) cart = JSON.parse(saved); } catch(e) { cart = []; } function saveCart() { localStorage.setItem(CART_KEY, JSON.stringify(cart)); updateCartUI(); } function getItemId(name, price) { return `${name}|||${price}`; } function addToCart(name, price, image) { const id = getItemId(name, price); const existing = cart.find(item => getItemId(item.name, item.price) === id); if (existing) { existing.quantity += 1; } else { cart.push({ name, price, quantity: 1, image }); } saveCart(); openCartSidebar(); } function removeFromCart(index) { cart.splice(index, 1); saveCart(); } function updateQuantity(index, delta) { if (cart[index]) { cart[index].quantity += delta; if (cart[index].quantity <= 0) { cart.splice(index, 1); } } saveCart(); } function getTotalItems() { return cart.reduce((sum, item) => sum + item.quantity, 0); } function getSubtotal() { return cart.reduce((sum, item) => sum + (item.price * item.quantity), 0); } function updateCartUI() { const totalItems = getTotalItems(); const subtotal = getSubtotal(); // Update all cart-count badges document.querySelectorAll('.cart-count-badge').forEach(badge => { badge.textContent = totalItems; badge.style.display = totalItems > 0 ? 'flex' : 'none'; }); // Update cart sidebar items const cartItemsContainer = document.getElementById('cart-items-container'); const cartSubtotalEl = document.getElementById('cart-subtotal'); const cartTotalEl = document.getElementById('cart-total'); const cartEmptyMsg = document.getElementById('cart-empty-message'); const cartHasItems = document.getElementById('cart-has-items'); const cartFooter = document.getElementById('cart-footer-section'); if (cartItemsContainer) { if (cart.length === 0) { cartItemsContainer.innerHTML = ''; if (cartEmptyMsg) cartEmptyMsg.classList.remove('hidden'); if (cartHasItems) cartHasItems.classList.add('hidden'); if (cartFooter) cartFooter.classList.add('hidden'); } else { if (cartEmptyMsg) cartEmptyMsg.classList.add('hidden'); if (cartHasItems) cartHasItems.classList.remove('hidden'); if (cartFooter) cartFooter.classList.remove('hidden'); cartItemsContainer.innerHTML = cart.map((item, index) => `
${item.image ? `${item.name}` : ''}

${item.name}

PEN ${item.price.toFixed(2)} c/u

${item.quantity}

PEN ${(item.price * item.quantity).toFixed(2)}

`).join(''); } } if (cartSubtotalEl) cartSubtotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; if (cartTotalEl) cartTotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; } function openCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.add('open'); if (overlay) overlay.classList.add('active'); document.body.style.overflow = 'hidden'; } function closeCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.remove('open'); if (overlay) overlay.classList.remove('active'); document.body.style.overflow = ''; } // ==================== INITIALIZE ==================== function initCart() { // Create cart sidebar HTML if it doesn't exist if (!document.getElementById('cart-sidebar')) { const cartHTML = `

Tu Carrito 14

`; document.body.insertAdjacentHTML('beforeend', cartHTML); } // Create cart toggle button if it doesn't exist if (!document.getElementById('cart-toggle-btn')) { const cartToggleHTML = ` `; document.body.insertAdjacentHTML('beforeend', cartToggleHTML); } // Attach event listeners const cartToggleBtn = document.getElementById('cart-toggle-btn'); const cartCloseBtn = document.getElementById('cart-close-btn'); const cartOverlay = document.getElementById('cart-overlay'); const cartCheckoutBtn = document.getElementById('cart-checkout-btn'); if (cartToggleBtn) cartToggleBtn.addEventListener('click', openCartSidebar); if (cartCloseBtn) cartCloseBtn.addEventListener('click', closeCartSidebar); if (cartOverlay) cartOverlay.addEventListener('click', closeCartSidebar); // Delegate events for cart item buttons const cartSidebar = document.getElementById('cart-sidebar'); if (cartSidebar) { cartSidebar.addEventListener('click', function(e) { const btn = e.target.closest('button'); if (!btn) return; const action = btn.getAttribute('data-action'); const index = parseInt(btn.getAttribute('data-index')); if (isNaN(index)) return; if (action === 'increase') updateQuantity(index, 1); else if (action === 'decrease') updateQuantity(index, -1); else if (action === 'remove') removeFromCart(index); }); } // Checkout button if (cartCheckoutBtn) { cartCheckoutBtn.addEventListener('click', function() { if (cart.length === 0) return; let message = 'Hola! Quisiera hacer el siguiente pedido:%0A%0A'; cart.forEach((item, i) => { message += `${i+1}. ${item.name} x${item.quantity} - PEN ${(item.price * item.quantity).toFixed(2)}%0A`; }); message += `%0A*Total: PEN ${getSubtotal().toFixed(2)}*`; window.open(`https://wa.me/?text=${message}`, '_blank'); }); } // Connect all "Añadir" buttons document.querySelectorAll('.add-to-order-button').forEach(button => { button.addEventListener('click', function(e) { e.preventDefault(); const menuItem = this.closest('.menu-item'); if (!menuItem) return; const nameEl = menuItem.querySelector('h3'); const priceEl = menuItem.querySelector('.text-primary-red, span.text-2xl.font-bold'); const imgEl = menuItem.querySelector('img'); const name = nameEl ? nameEl.textContent.trim() : 'Producto'; const priceText = priceEl ? priceEl.textContent.trim() : 'PEN 0.00'; const price = parseFloat(priceText.replace(/[^0-9.]/g, '')); const image = imgEl ? imgEl.getAttribute('src') : ''; if (name && !isNaN(price)) { addToCart(name, price, image); // Visual feedback this.classList.add('scale-95', 'bg-yellow-600'); setTimeout(() => { this.classList.remove('scale-95', 'bg-yellow-600'); }, 200); } }); }); // Keyboard shortcut to close cart document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeCartSidebar(); }); // Initial UI update updateCartUI(); } // Run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCart); } else { initCart(); } })(); ======= // ==================== CART SYSTEM ==================== (function() { const CART_KEY = 'arepaCafeCart'; // Load cart from localStorage or initialize empty let cart = []; try { const saved = localStorage.getItem(CART_KEY); if (saved) cart = JSON.parse(saved); } catch(e) { cart = []; } function saveCart() { localStorage.setItem(CART_KEY, JSON.stringify(cart)); updateCartUI(); } function getItemId(name, price) { return `${name.trim()}|||${price}`; } function addToCart(name, price, image) { const id = getItemId(name, price); const existing = cart.find(item => getItemId(item.name, item.price) === id); if (existing) { existing.quantity += 1; } else { cart.push({ name: name.trim(), price, quantity: 1, image }); } saveCart(); openCartSidebar(); } function removeFromCart(index) { if (index >= 0 && index < cart.length) { cart.splice(index, 1); saveCart(); } } function updateQuantity(index, delta) { if (index >= 0 && index < cart.length) { cart[index].quantity += delta; if (cart[index].quantity <= 0) { cart.splice(index, 1); } saveCart(); } } function getTotalItems() { return cart.reduce((sum, item) => sum + item.quantity, 0); } function getSubtotal() { return cart.reduce((sum, item) => sum + (item.price * item.quantity), 0); } function updateCartUI() { const totalItems = getTotalItems(); const subtotal = getSubtotal(); // Update all cart-count badges const allBadges = document.querySelectorAll('.cart-count-badge'); allBadges.forEach(badge => { badge.textContent = totalItems; badge.style.display = totalItems > 0 ? 'inline-flex' : 'none'; }); // Update cart sidebar items const cartItemsContainer = document.getElementById('cart-items-container'); const cartSubtotalEl = document.getElementById('cart-subtotal'); const cartTotalEl = document.getElementById('cart-total'); const cartEmptyMsg = document.getElementById('cart-empty-message'); const cartHasItems = document.getElementById('cart-has-items'); const cartFooter = document.getElementById('cart-footer-section'); if (!cartItemsContainer) return; if (cart.length === 0) { cartItemsContainer.innerHTML = ''; if (cartEmptyMsg) cartEmptyMsg.classList.remove('hidden'); if (cartHasItems) cartHasItems.classList.add('hidden'); if (cartFooter) cartFooter.classList.add('hidden'); } else { if (cartEmptyMsg) cartEmptyMsg.classList.add('hidden'); if (cartHasItems) cartHasItems.classList.remove('hidden'); if (cartFooter) cartFooter.classList.remove('hidden'); cartItemsContainer.innerHTML = cart.map((item, index) => { const lineTotal = item.price * item.quantity; const imgTag = item.image ? `${item.name}` : `
`; return `
${imgTag}

${item.name}

PEN ${item.price.toFixed(2)} c/u

${item.quantity}

PEN ${lineTotal.toFixed(2)}

`; }).join(''); } if (cartSubtotalEl) cartSubtotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; if (cartTotalEl) cartTotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; } function openCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) { sidebar.classList.add('open'); updateCartUI(); } if (overlay) overlay.classList.add('active'); document.body.style.overflow = 'hidden'; } function closeCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.remove('open'); if (overlay) overlay.classList.remove('active'); document.body.style.overflow = ''; } // ==================== INITIALIZE ==================== function initCart() { // Create cart sidebar HTML if it doesn't exist if (!document.getElementById('cart-sidebar')) { const cartHTML = `

Tu Carrito 14

Tu carrito está vacío

¡Agrega algo delicioso del menú!

`; document.body.insertAdjacentHTML('beforeend', cartHTML); } // Create cart toggle button if it doesn't exist if (!document.getElementById('cart-toggle-btn')) { const cartToggleHTML = ` `; document.body.insertAdjacentHTML('beforeend', cartToggleHTML); } // Attach event listeners const cartToggleBtn = document.getElementById('cart-toggle-btn'); const cartCloseBtn = document.getElementById('cart-close-btn'); const cartOverlay = document.getElementById('cart-overlay'); const cartCheckoutBtn = document.getElementById('cart-checkout-btn'); if (cartToggleBtn) cartToggleBtn.addEventListener('click', openCartSidebar); if (cartCloseBtn) cartCloseBtn.addEventListener('click', closeCartSidebar); if (cartOverlay) cartOverlay.addEventListener('click', closeCartSidebar); // Delegate events for cart item buttons const cartSidebar = document.getElementById('cart-sidebar'); if (cartSidebar) { cartSidebar.addEventListener('click', function(e) { const btn = e.target.closest('button'); if (!btn) return; const action = btn.getAttribute('data-action'); const index = parseInt(btn.getAttribute('data-index')); if (isNaN(index)) return; if (action === 'increase') updateQuantity(index, 1); else if (action === 'decrease') updateQuantity(index, -1); else if (action === 'remove') removeFromCart(index); }); } // Checkout button - open WhatsApp with order summary if (cartCheckoutBtn) { cartCheckoutBtn.addEventListener('click', function() { if (cart.length === 0) return; let message = '🍽️ *Hola! Quisiera hacer el siguiente pedido:*%0A%0A'; cart.forEach((item, i) => { const lineTotal = (item.price * item.quantity).toFixed(2); message += `*${i+1}.* ${item.name}%0A`; message += ` ${item.quantity} x PEN ${item.price.toFixed(2)} = PEN ${lineTotal}%0A%0A`; }); message += `%0A—————————————%0A`; message += `💰 *TOTAL: PEN ${getSubtotal().toFixed(2)}*%0A`; message += `📦 *Items: ${getTotalItems()}*%0A`; message += `%0A—————————————%0A`; message += `%0A¡Gracias! 🙌`; window.open(`https://wa.me/51999999999?text=${message}`, '_blank'); }); } // Connect all "Añadir" buttons with clean event handling function connectAddButtons() { document.querySelectorAll('.add-to-order-button').forEach(button => { // Remove existing listener by cloning (avoids duplicates on re-init) const newButton = button.cloneNode(true); button.parentNode.replaceChild(newButton, button); newButton.addEventListener('click', function(e) { e.preventDefault(); e.stopPropagation(); const menuItem = this.closest('.menu-item'); if (!menuItem) return; const nameEl = menuItem.querySelector('h3'); const imgEl = menuItem.querySelector('img'); // Find price - look for the span with text-primary-red class const priceEl = menuItem.querySelector('span.text-primary-red'); const name = nameEl ? nameEl.textContent.replace(/\s+/g, ' ').trim() : 'Producto'; const priceText = priceEl ? priceEl.textContent.replace(/\s+/g, ' ').trim() : 'PEN 0.00'; // Extract number from price text (handles PEN, S/, etc.) const priceMatch = priceText.match(/(\d+\.?\d*)/); const price = priceMatch ? parseFloat(priceMatch[1]) : 0; const image = imgEl ? imgEl.getAttribute('src') : ''; if (name && price > 0) { addToCart(name, price, image); // Visual feedback - brief pulse animation this.style.transform = 'scale(0.9)'; this.style.backgroundColor = '#eab308'; this.style.transition = 'all 0.15s ease'; setTimeout(() => { this.style.transform = 'scale(1)'; this.style.backgroundColor = ''; }, 200); } }); }); } connectAddButtons(); // Keyboard shortcut to close cart document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeCartSidebar(); }); // Initial UI update updateCartUI(); } // Run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCart); } else { initCart(); } })(); ======= // ==================== CART SYSTEM ==================== (function() { const CART_KEY = 'arepaCafeCart'; // Load cart from localStorage or initialize empty let cart = []; try { const saved = localStorage.getItem(CART_KEY); if (saved) cart = JSON.parse(saved); } catch(e) { cart = []; } function saveCart() { localStorage.setItem(CART_KEY, JSON.stringify(cart)); updateCartUI(); } function getItemId(name, price) { return `${name}|||${price}`; } function addToCart(name, price, image) { const id = getItemId(name, price); const existing = cart.find(item => getItemId(item.name, item.price) === id); if (existing) { existing.quantity += 1; } else { cart.push({ name, price, quantity: 1, image }); } saveCart(); openCartSidebar(); } function removeFromCart(index) { cart.splice(index, 1); saveCart(); } function updateQuantity(index, delta) { if (cart[index]) { cart[index].quantity += delta; if (cart[index].quantity <= 0) { cart.splice(index, 1); } } saveCart(); } function getTotalItems() { return cart.reduce((sum, item) => sum + item.quantity, 0); } function getSubtotal() { return cart.reduce((sum, item) => sum + (item.price * item.quantity), 0); } function updateCartUI() { const totalItems = getTotalItems(); const subtotal = getSubtotal(); // Update all cart-count badges document.querySelectorAll('.cart-count-badge').forEach(badge => { badge.textContent = totalItems; badge.style.display = totalItems > 0 ? 'flex' : 'none'; }); // Update cart sidebar items const cartItemsContainer = document.getElementById('cart-items-container'); const cartSubtotalEl = document.getElementById('cart-subtotal'); const cartTotalEl = document.getElementById('cart-total'); const cartEmptyMsg = document.getElementById('cart-empty-message'); const cartHasItems = document.getElementById('cart-has-items'); const cartFooter = document.getElementById('cart-footer-section'); if (cartItemsContainer) { if (cart.length === 0) { cartItemsContainer.innerHTML = ''; if (cartEmptyMsg) cartEmptyMsg.classList.remove('hidden'); if (cartHasItems) cartHasItems.classList.add('hidden'); if (cartFooter) cartFooter.classList.add('hidden'); } else { if (cartEmptyMsg) cartEmptyMsg.classList.add('hidden'); if (cartHasItems) cartHasItems.classList.remove('hidden'); if (cartFooter) cartFooter.classList.remove('hidden'); cartItemsContainer.innerHTML = cart.map((item, index) => `
${item.image ? `${item.name}` : ''}

${item.name}

PEN ${item.price.toFixed(2)} c/u

${item.quantity}

PEN ${(item.price * item.quantity).toFixed(2)}

`).join(''); } } if (cartSubtotalEl) cartSubtotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; if (cartTotalEl) cartTotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; } function openCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.add('open'); if (overlay) overlay.classList.add('active'); document.body.style.overflow = 'hidden'; } function closeCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.remove('open'); if (overlay) overlay.classList.remove('active'); document.body.style.overflow = ''; } // ==================== INITIALIZE ==================== function initCart() { // Create cart sidebar HTML if it doesn't exist if (!document.getElementById('cart-sidebar')) { const cartHTML = `

Tu Pedido 14

Tu carrito está vacío

¡Agrega algo delicioso del menú!

`; document.body.insertAdjacentHTML('beforeend', cartHTML); } // Create cart toggle button if it doesn't exist if (!document.getElementById('cart-toggle-btn')) { const cartToggleHTML = ` `; document.body.insertAdjacentHTML('beforeend', cartToggleHTML); } // Attach event listeners const cartToggleBtn = document.getElementById('cart-toggle-btn'); const cartCloseBtn = document.getElementById('cart-close-btn'); const cartOverlay = document.getElementById('cart-overlay'); const cartCheckoutBtn = document.getElementById('cart-checkout-btn'); if (cartToggleBtn) cartToggleBtn.addEventListener('click', openCartSidebar); if (cartCloseBtn) cartCloseBtn.addEventListener('click', closeCartSidebar); if (cartOverlay) cartOverlay.addEventListener('click', closeCartSidebar); // Delegate events for cart item buttons const cartSidebar = document.getElementById('cart-sidebar'); if (cartSidebar) { cartSidebar.addEventListener('click', function(e) { const btn = e.target.closest('button'); if (!btn) return; const action = btn.getAttribute('data-action'); const index = parseInt(btn.getAttribute('data-index')); if (isNaN(index)) return; if (action === 'increase') updateQuantity(index, 1); else if (action === 'decrease') updateQuantity(index, -1); else if (action === 'remove') removeFromCart(index); }); } // Checkout button if (cartCheckoutBtn) { cartCheckoutBtn.addEventListener('click', function() { if (cart.length === 0) return; let message = 'Hola! Quisiera hacer el siguiente pedido:%0A%0A'; cart.forEach((item, i) => { message += `${i+1}. ${item.name} x${item.quantity} - PEN ${(item.price * item.quantity).toFixed(2)}%0A`; }); message += `%0A*Total: PEN ${getSubtotal().toFixed(2)}*`; window.open(`https://wa.me/?text=${message}`, '_blank'); }); } // Connect all "Añadir" buttons document.querySelectorAll('.add-to-order-button').forEach(button => { button.addEventListener('click', function(e) { e.preventDefault(); const menuItem = this.closest('.menu-item'); if (!menuItem) return; const nameEl = menuItem.querySelector('h3'); const priceEl = menuItem.querySelector('.text-primary-red, span.text-2xl.font-bold'); const imgEl = menuItem.querySelector('img'); const name = nameEl ? nameEl.textContent.trim() : 'Producto'; const priceText = priceEl ? priceEl.textContent.trim() : 'PEN 0.00'; const price = parseFloat(priceText.replace(/[^0-9.]/g, '')); const image = imgEl ? imgEl.getAttribute('src') : ''; if (name && !isNaN(price)) { addToCart(name, price, image); // Visual feedback this.classList.add('scale-95', 'bg-yellow-600'); setTimeout(() => { this.classList.remove('scale-95', 'bg-yellow-600'); }, 200); } }); }); // Keyboard shortcut to close cart document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeCartSidebar(); }); // Initial UI update updateCartUI(); } // Run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCart); } else { initCart(); } })(); ====== CART SYSTEM ==================== (function() { const CART_KEY = 'arepaCafeCart'; // Load cart from localStorage or initialize empty let cart = []; try { const saved = localStorage.getItem(CART_KEY); if (saved) cart = JSON.parse(saved); } catch(e) { cart = []; } function saveCart() { localStorage.setItem(CART_KEY, JSON.stringify(cart)); updateCartUI(); } function getItemId(name, price) { return `${name}|||${price}`; } function addToCart(name, price, image) { const id = getItemId(name, price); const existing = cart.find(item => getItemId(item.name, item.price) === id); if (existing) { existing.quantity += 1; } else { cart.push({ name, price, quantity: 1, image }); } saveCart(); openCartSidebar(); } function removeFromCart(index) { cart.splice(index, 1); saveCart(); } function updateQuantity(index, delta) { if (cart[index]) { cart[index].quantity += delta; if (cart[index].quantity <= 0) { cart.splice(index, 1); } } saveCart(); } function getTotalItems() { return cart.reduce((sum, item) => sum + item.quantity, 0); } function getSubtotal() { return cart.reduce((sum, item) => sum + (item.price * item.quantity), 0); } function updateCartUI() { const totalItems = getTotalItems(); const subtotal = getSubtotal(); // Update all cart-count badges document.querySelectorAll('.cart-count-badge').forEach(badge => { badge.textContent = totalItems; badge.style.display = totalItems > 0 ? 'flex' : 'none'; }); // Update cart sidebar items const cartItemsContainer = document.getElementById('cart-items-container'); const cartSubtotalEl = document.getElementById('cart-subtotal'); const cartTotalEl = document.getElementById('cart-total'); const cartEmptyMsg = document.getElementById('cart-empty-message'); const cartHasItems = document.getElementById('cart-has-items'); const cartFooter = document.getElementById('cart-footer-section'); if (cartItemsContainer) { if (cart.length === 0) { cartItemsContainer.innerHTML = ''; if (cartEmptyMsg) cartEmptyMsg.classList.remove('hidden'); if (cartHasItems) cartHasItems.classList.add('hidden'); if (cartFooter) cartFooter.classList.add('hidden'); } else { if (cartEmptyMsg) cartEmptyMsg.classList.add('hidden'); if (cartHasItems) cartHasItems.classList.remove('hidden'); if (cartFooter) cartFooter.classList.remove('hidden'); cartItemsContainer.innerHTML = cart.map((item, index) => `
${item.image ? `${item.name}` : ''}

${item.name}

PEN ${item.price.toFixed(2)} c/u

${item.quantity}

PEN ${(item.price * item.quantity).toFixed(2)}

`).join(''); } } if (cartSubtotalEl) cartSubtotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; if (cartTotalEl) cartTotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; } function openCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.add('open'); if (overlay) overlay.classList.add('active'); document.body.style.overflow = 'hidden'; } function closeCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.remove('open'); if (overlay) overlay.classList.remove('active'); document.body.style.overflow = ''; } // ==================== INITIALIZE ==================== function initCart() { // Create cart sidebar HTML if it doesn't exist if (!document.getElementById('cart-sidebar')) { const cartHTML = `

Tu Carrito 14

`; document.body.insertAdjacentHTML('beforeend', cartHTML); } // Create cart toggle button if it doesn't exist if (!document.getElementById('cart-toggle-btn')) { const cartToggleHTML = ` `; document.body.insertAdjacentHTML('beforeend', cartToggleHTML); } // Attach event listeners const cartToggleBtn = document.getElementById('cart-toggle-btn'); const cartCloseBtn = document.getElementById('cart-close-btn'); const cartOverlay = document.getElementById('cart-overlay'); const cartCheckoutBtn = document.getElementById('cart-checkout-btn'); if (cartToggleBtn) cartToggleBtn.addEventListener('click', openCartSidebar); if (cartCloseBtn) cartCloseBtn.addEventListener('click', closeCartSidebar); if (cartOverlay) cartOverlay.addEventListener('click', closeCartSidebar); // Delegate events for cart item buttons const cartSidebar = document.getElementById('cart-sidebar'); if (cartSidebar) { cartSidebar.addEventListener('click', function(e) { const btn = e.target.closest('button'); if (!btn) return; const action = btn.getAttribute('data-action'); const index = parseInt(btn.getAttribute('data-index')); if (isNaN(index)) return; if (action === 'increase') updateQuantity(index, 1); else if (action === 'decrease') updateQuantity(index, -1); else if (action === 'remove') removeFromCart(index); }); } // Checkout button if (cartCheckoutBtn) { cartCheckoutBtn.addEventListener('click', function() { if (cart.length === 0) return; let message = 'Hola! Quisiera hacer el siguiente pedido:%0A%0A'; cart.forEach((item, i) => { message += `${i+1}. ${item.name} x${item.quantity} - PEN ${(item.price * item.quantity).toFixed(2)}%0A`; }); message += `%0A*Total: PEN ${getSubtotal().toFixed(2)}*`; window.open(`https://wa.me/?text=${message}`, '_blank'); }); } // Connect all "Añadir" buttons document.querySelectorAll('.add-to-order-button').forEach(button => { button.addEventListener('click', function(e) { e.preventDefault(); const menuItem = this.closest('.menu-item'); if (!menuItem) return; const nameEl = menuItem.querySelector('h3'); const priceEl = menuItem.querySelector('.text-primary-red, span.text-2xl.font-bold'); const imgEl = menuItem.querySelector('img'); const name = nameEl ? nameEl.textContent.trim() : 'Producto'; const priceText = priceEl ? priceEl.textContent.trim() : 'PEN 0.00'; const price = parseFloat(priceText.replace(/[^0-9.]/g, '')); const image = imgEl ? imgEl.getAttribute('src') : ''; if (name && !isNaN(price)) { addToCart(name, price, image); // Visual feedback this.classList.add('scale-95', 'bg-yellow-600'); setTimeout(() => { this.classList.remove('scale-95', 'bg-yellow-600'); }, 200); } }); }); // Keyboard shortcut to close cart document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeCartSidebar(); }); // Initial UI update updateCartUI(); } // Run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCart); } else { initCart(); } })(); ======= ======= // ==================== CART SYSTEM ==================== (function() { const CART_KEY = 'arepaCafeCart'; // Load cart from localStorage or initialize empty let cart = []; try { const saved = localStorage.getItem(CART_KEY); if (saved) cart = JSON.parse(saved); } catch(e) { cart = []; } function saveCart() { localStorage.setItem(CART_KEY, JSON.stringify(cart)); updateCartUI(); } function getItemId(name, price) { return `${name.trim()}|||${price}`; } function addToCart(name, price, image) { const id = getItemId(name, price); const existing = cart.find(item => getItemId(item.name, item.price) === id); if (existing) { existing.quantity += 1; } else { cart.push({ name: name.trim(), price, quantity: 1, image }); } saveCart(); openCartSidebar(); } function removeFromCart(index) { if (index >= 0 && index < cart.length) { cart.splice(index, 1); saveCart(); } } function updateQuantity(index, delta) { if (index >= 0 && index < cart.length) { cart[index].quantity += delta; if (cart[index].quantity <= 0) { cart.splice(index, 1); } saveCart(); } } function getTotalItems() { return cart.reduce((sum, item) => sum + item.quantity, 0); } function getSubtotal() { return cart.reduce((sum, item) => sum + (item.price * item.quantity), 0); } function updateCartUI() { const totalItems = getTotalItems(); const subtotal = getSubtotal(); // Update all cart-count badges const allBadges = document.querySelectorAll('.cart-count-badge'); allBadges.forEach(badge => { badge.textContent = totalItems; badge.style.display = totalItems > 0 ? 'inline-flex' : 'none'; }); // Update cart sidebar items const cartItemsContainer = document.getElementById('cart-items-container'); const cartSubtotalEl = document.getElementById('cart-subtotal'); const cartTotalEl = document.getElementById('cart-total'); const cartEmptyMsg = document.getElementById('cart-empty-message'); const cartHasItems = document.getElementById('cart-has-items'); const cartFooter = document.getElementById('cart-footer-section'); if (!cartItemsContainer) return; if (cart.length === 0) { cartItemsContainer.innerHTML = ''; if (cartEmptyMsg) cartEmptyMsg.classList.remove('hidden'); if (cartHasItems) cartHasItems.classList.add('hidden'); if (cartFooter) cartFooter.classList.add('hidden'); } else { if (cartEmptyMsg) cartEmptyMsg.classList.add('hidden'); if (cartHasItems) cartHasItems.classList.remove('hidden'); if (cartFooter) cartFooter.classList.remove('hidden'); cartItemsContainer.innerHTML = cart.map((item, index) => { const lineTotal = item.price * item.quantity; const imgTag = item.image ? `` : `
`; return `
${imgTag}

${item.name}

PEN ${item.price.toFixed(2)} c/u

${item.quantity}

PEN ${lineTotal.toFixed(2)}

`; }).join(''); } if (cartSubtotalEl) cartSubtotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; if (cartTotalEl) cartTotalEl.textContent = `PEN ${subtotal.toFixed(2)}`; } function openCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) { sidebar.classList.add('open'); // Ensure cart UI is refreshed when opening updateCartUI(); } if (overlay) overlay.classList.add('active'); document.body.style.overflow = 'hidden'; } function closeCartSidebar() { const sidebar = document.getElementById('cart-sidebar'); const overlay = document.getElementById('cart-overlay'); if (sidebar) sidebar.classList.remove('open'); if (overlay) overlay.classList.remove('active'); document.body.style.overflow = ''; } // ==================== INITIALIZE ==================== function initCart() { // Create cart sidebar HTML if it doesn't exist if (!document.getElementById('cart-sidebar')) { const cartHTML = `

Tu Pedido 14

Tu carrito está vacío

¡Agrega algo delicioso del menú!

`; document.body.insertAdjacentHTML('beforeend', cartHTML); } // Create cart toggle button if it doesn't exist if (!document.getElementById('cart-toggle-btn')) { const cartToggleHTML = ` `; document.body.insertAdjacentHTML('beforeend', cartToggleHTML); } // Attach event listeners const cartToggleBtn = document.getElementById('cart-toggle-btn'); const cartCloseBtn = document.getElementById('cart-close-btn'); const cartOverlay = document.getElementById('cart-overlay'); const cartCheckoutBtn = document.getElementById('cart-checkout-btn'); if (cartToggleBtn) cartToggleBtn.addEventListener('click', openCartSidebar); if (cartCloseBtn) cartCloseBtn.addEventListener('click', closeCartSidebar); if (cartOverlay) cartOverlay.addEventListener('click', closeCartSidebar); // Delegate events for cart item buttons const cartSidebar = document.getElementById('cart-sidebar'); if (cartSidebar) { cartSidebar.addEventListener('click', function(e) { const btn = e.target.closest('button'); if (!btn) return; const action = btn.getAttribute('data-action'); const index = parseInt(btn.getAttribute('data-index')); if (isNaN(index)) return; if (action === 'increase') updateQuantity(index, 1); else if (action === 'decrease') updateQuantity(index, -1); else if (action === 'remove') removeFromCart(index); }); } // Checkout button - open WhatsApp with order summary if (cartCheckoutBtn) { cartCheckoutBtn.addEventListener('click', function() { if (cart.length === 0) return; let message = '🍽️ *Hola! Quisiera hacer el siguiente pedido:*%0A%0A'; cart.forEach((item, i) => { const lineTotal = (item.price * item.quantity).toFixed(2); message += `*${i+1}.* ${item.name}%0A`; message += ` ${item.quantity} x PEN ${item.price.toFixed(2)} = PEN ${lineTotal}%0A%0A`; }); message += `%0A—————————————%0A`; message += `💰 *TOTAL: PEN ${getSubtotal().toFixed(2)}*%0A`; message += `📦 *Items: ${getTotalItems()}*%0A`; message += `%0A—————————————%0A`; message += `%0A¡Gracias! 🙌`; window.open(`https://wa.me/51999999999?text=${message}`, '_blank'); }); } // Connect all "Añadir" buttons function connectAddButtons() { document.querySelectorAll('.add-to-order-button').forEach(button => { // Remove existing listener by cloning (avoids duplicates on re-init) const newButton = button.cloneNode(true); button.parentNode.replaceChild(newButton, button); newButton.addEventListener('click', function(e) { e.preventDefault(); e.stopPropagation(); const menuItem = this.closest('.menu-item'); if (!menuItem) return; const nameEl = menuItem.querySelector('h3'); const imgEl = menuItem.querySelector('img'); // Find price - look for the span with text-primary-red and text-2xl font-bold const priceEl = menuItem.querySelector('span.text-primary-red.text-2xl, span.text-2xl.font-bold.text-primary-red, span.text-primary-red'); const name = nameEl ? nameEl.textContent.replace(/\s+/g, ' ').trim() : 'Producto'; const priceText = priceEl ? priceEl.textContent.replace(/\s+/g, ' ').trim() : 'PEN 0.00'; // Extract number from price text (handles PEN, S/, etc.) const priceMatch = priceText.match(/(\d+\.?\d*)/); const price = priceMatch ? parseFloat(priceMatch[1]) : 0; const image = imgEl ? imgEl.getAttribute('src') : ''; if (name && price > 0) { addToCart(name, price, image); // Visual feedback - brief pulse animation this.style.transform = 'scale(0.9)'; this.style.backgroundColor = '#eab308'; this.style.transition = 'all 0.15s ease'; setTimeout(() => { this.style.transform = 'scale(1)'; this.style.backgroundColor = ''; }, 200); } }); }); } connectAddButtons(); // Keyboard shortcut to close cart document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeCartSidebar(); }); // Initial UI update updateCartUI(); } // Run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCart); } else { initCart(); } })();

We use cookies and similar technologies to improve your browsing experience and personalize content. By continuing to use our site, you agree to our use of cookies.