Las mejores arepas, hechas con amor y los ingredientes más frescos, directo a tu puerta en Lima.
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.
Sabores que te transportarán directo a Venezuela. Elige tu favorita y disfrútala en casa.
La Arepa Taco
Arepa venezolana recién hecha rellena de jugosa carne mechada y abundante queso amarillo rallado. Un clásico lleno de sabor.
PEN 28.50
Pabellón Vegetariano ⭐
Nuestra versión Vegetariana del clásico venezolano con caraotas negras, queso blanco , plátano frito y abundante aguacate fresco. Abundante y lleno de sabor.
PEN 28.90
🥇 COMBO REINA PEPIADA + BEBIDA
🔥 EL COMBO MÁS PEDIDO 😍 Nuestra icónica Reina Pepiada 👑 Pollo desmenuzado con cremosa salsa de aguacate 🥑, suave y jugosa 🤤 Acompañada de una bebida bien fría 🥤❄️ 💣 La combinación perfecta para quedar satisfecho ⚡ Rápido, práctico y brutal 🔥 Ahorra y disfruta más en combo
PEN 29.90
🥭 Jugo de Maracuyá
Jugo natural de maracuyá fresco, refrescante, tropical y con el balance perfecto entre dulce y ácido.
PEN 11.00
🌽 Cachapa
Nuestra cachapa venezolana hecha con maíz dulce fresco, dorada a la plancha con mantequilla y rellena con queso de mano suave y derretido. Un clásico irresistible.
PEN 34.90
Arepa de Pabellón
La arepa más emblemática de Venezuela: carne mechada, caraotas negras cremosas, plátano maduro frito y queso blanco rallado ! Es una de las mas pedidas!
PEN 28.50
🔥 Arepa Pelúa ⭐
Carne mechada venezolana jugosa con abundante queso rallado derretido dentro de nuestra arepa recién hecha. Una de las más pedidas!
PEN 27.50
Arepa Llanera
Carne jugosa con queso de mano y pico de gallo con aguacate fresco , dentro de nuestra arepa dorada por fuera y suave por dentro. ⭐ Una de las favoritas de nuestros clientes.
PEN 29.90
Reina Peruana
Nuestra fusión especial: pollo desmechado con palta cremosa cubierto en Huancaina coronado con queso Gouda Importado inspirado en sabores peruanos.
PEN 29.50
🍗 Catira
Pollo desmechado jugoso acompañado de queso Gouda Importado derretido dentro de una arepa recién hecha.
PEN 27.50
🧀 Sifrina
La Reina Pepiada elevada al máximo: pollo con palta cremosa coronado con abundante queso amarillo rallado.
PEN 28.50
🥑 Reina Pepiada
🔥 LA ESTRELLA DE LA CASA Nuestra famosa Reina Pepiada 👑 Pollo Organico desmenuzado mezclado con mayonesa de la casa y cremosa salsa de aguacate 🥑 y coronado con Mas Aguacate !!! Suave, jugosa y llena de sabor 🤤 Perfecta para tu primera vez
PEN 25.50
🥑 Reina Pepiada Jr ⭐
Arepa pequeña rellena con pollo desmechado y aguacate cremoso, fresca, suave y llena de sabor. Versión perfecta para un antojo rápido!
PEN 17.90
Domino
La clásica combinación venezolana de caraotas negras cremosas con queso blanco rallado. Simple, auténtica y deliciosa.
PEN 26.50
Arepa de Carne Mechada
Arepa venezolana recién hecha, con mantequilla y rellena de jugosa carne mechada. Un clásico lleno de sabor.
PEN 25.50
Arepa de Queso Gouda
Arepa caliente con queso gouda rallado abundante, suave, cremoso y ligeramente derretido.
PEN 24.50
Arepa de Queso Llanero
Arepa venezolana recién hecha rellena con abundante queso llanero, salado y lleno de sabor. Un clásico sencillo y delicioso.
PEN 24.50
Queso de Mano
Nuestra arepa rellena con abundante queso de mano suave y fresco. Un favorito tradicional venezolano.
PEN 24.50
El Gato ⭐
Arepa rellena con abundante queso de Mano, platanos fritos y Palta. Sabor tradicional venezolano. 🥑
PEN 28.90
🥇 COMBO PELÚA + BEBIDA
🔥 EL COMBO MÁS BRUTAL 😍 Nuestra poderosa Pelúa 💣 Carne mechada jugosa con queso Gouda importado derretido 🧀🔥 Intensa, llena de sabor y bien resuelta 🤤 Acompañada de una gaseosa bien fría 🥤❄️ 💣 Sabor fuerte que te deja satisfecho 🔥 Perfecta para los que quieren comer bien ⭐ Uno de los combos más pedidos
PEN 29.90
🍗 Emp. Pollo
Empanada venezolana auténtica, rellena con jugoso pollo sazonado al estilo tradicional, envuelta en una masa doradita y crujiente. Un bocado lleno de sabor, aroma y ese toque casero que conquista desde la primera mordida.
PEN 23.90
🥩 Emp. Molida
Carne molida jugosa y bien condimentada, envuelta en una empanada dorada y crujiente. Un favorito lleno de sabor casero.
PEN 23.90
🧀 Emp. Queso
Queso derretido dentro de una empanada dorada y crujiente, recién frita y llena de sabor. Un clásico simple pero irresistible.
PEN 20.90
🫘🧀 Emp. Dominó
Caraotas negras cremosas con queso blanco, dentro de una empanada dorada y crujiente. Un clásico venezolano lleno de sabor.
PEN 23.90
Emp. Pabellón
Carne mechada, caraotas negras, plátano frito y queso dentro de una empanada abundante y crujiente. Todo el sabor del pabellón en cada bocado. Pesa 1/2k
PEN 25.90
🍌🧀 Emp. Plátano & Queso
Plátano maduro dorado con queso derretido, dentro de una empanada crujiente recién hecha. ⭐ Las más pedidas por nuestros clientes
PEN 23.90
🧀 Tequeños 1/2 Docena
6 tequeños doraditos y crujientes rellenos con queso derretido, recién fritos y perfectos para compartir… o no.
PEN 25.90
🧀 Tequeños 1 Docena
12 tequeños crujientes con queso derretido en cada bocado. El acompañante perfecto para cualquier pedido.
PEN 41.90
🧀 Tequeños Congelados 1/2 Docena
6 tequeños listos para freír en casa con auténtico queso venezolano. Perfectos para disfrutar cuando quieras.
PEN 23.90
🧀 Tequeños Congelados 1 Docena
12 tequeños congelados con queso venezolano, listos para freír y disfrutar recién hechos en casa.
PEN 39.90
🍓 Jugo de Fresa
Jugos naturales recién preparados y bien fríos, perfectos para acompañar tu comida.
PEN 15.00
🥛 Chicha Venezolana
Bebida cremosa y fría hecha con arroz, leche y un toque de canela, dulce, suave y muy tradicional. Un sabor parecido a arroz con leche, un clásico venezolano irresistible.
PEN 15.00
🍋 Papelón con Limón
Refrescante bebida venezolana de papelón natural con limón fresco, dulce, cítrica y muy refrescante. El acompañante perfecto para tu arepa. 1/2 Lt
PEN 11.00
🟤 Malta Polar Venezolana
Malta Polar venezolana, bebida carbonatada con un distintivo sabor a malta y caramelo. Refrescante y perfecta para acompañar tus comidas.
PEN 13.00
🔴 Frescolita Venezolana
La famosa Frescolita venezolana, refresco dulce con sabor único y muy tradicional. Un favorito que no puede faltar.
PEN 13.00
Agua San Mateo ( Agua Mineral )
Agua mineral San Mateo de 600 ml, pura y refrescante.
PEN 5.00
Agua San Mateo C/Gas ( Agua Mineral )
Agua San Mateo C/Gas ( Agua Mineral ) de 600 ml
PEN 5.00
Coca-Cola
Coca-Cola de 1/2 lt
PEN 6.00
Inka Kola
Inka Kola de 1/2 litro, el acompañante perfecto para tu arepa.
PEN 6.00
Fanta Naranja
Fanta Naranja de 1/2 Lt
PEN 6.00
Sprite
Sprite de 1/2 Lt
PEN 6.00
🧀 Cachapa Doble Queso
Cachapa caliente con abundante queso derretido en cada bocado. Simple, cremosa y absolutamente deliciosa. Con un 1/4k de Queso de Mano
PEN 39.90
🥩 Cachapa con Mechada
Cachapa dorada rellena con carne mechada venezolana jugosa y queso de Mano derretido. Una combinación abundante y llena de sabor.
PEN 39.90
🥓🧀 Cachapa Tocino con Queso
Cachapa dorada con tocino ahumado y crujiente con queso de Mano derretido, una combinación intensa y muy sabrosa.
PEN 42.90
🍌🧀 Cachapa con Plátano y Queso
Cachapa de maíz dulce acompañada con abundante plátano frito dorado y queso de mano derretido. La mezcla perfecta entre dulce y salado.
PEN 37.90
🧀 Cachapa Triple Queso
Cachapa de maíz dulce con tres capas de queso , queso de mano derretido, queso llanero rallado , y cremosa natilla por todo arriba, abundante y perfecta para los amantes del queso.
PEN 39.90
🧀🍖 Cachapa Jamón y Queso
Cachapa recién hecha rellena con jamón ahumado y queso de Mano derretido, cremosa y muy reconfortante.
PEN 38.90
🧀 Cachapa Jr. Triple Queso
Cachapa pequeña pero llena de sabor con tres capas de queso derretido. Chiquita pero irresistible.
PEN 30.90
🌽 Cachapa Jr.
Versión más pequeña de nuestra cachapa clásica de maíz dulce con queso derretido. Perfecta para un antojo rápido.
PEN 27.90
Reina Pepiada 👑
La más pedida de la casa. Pollo desmenuzado con cremosa salsa de aguacate, suave y jugosa. Nuestra estrella indiscutible.
PEN 26.00
Arepa de Pabellón 🇻🇪
El orgullo venezolano: carne mechada, caraotas negras, plátano maduro frito y queso blanco. Un estallido de sabor tradicional.
PEN 32.00
La Arepa Taco 🌮
Carne mechada jugosa y queso cheddar fundido. Una combinación que enamora a primera mordida.
PEN 28.50
Reina Peruana 🇵🇪
Una fusión único: pollo desmenuzado, aguacate, queso crema y un toque de ají amarillo. Un sabor que cruza fronteras.
PEN 27.00
Arepa Llanera 🔥
Pollo a la parrilla, queso cheddar derretido y tiras de bacon crujiente. Una explosión de sabor y textura.
PEN 29.50
Arepa de Queso Gouda 🧀
Queso gouda derretido con jamón ahumado y un toque de mostaza miel. Una delicia ahumada y cremosa.
PEN 31.50
Arepa Catira 🐔
Pollo desmenuzado con queso amarillo rallado. Simple, clásica y absolutamente deliciosa.
PEN 22.00
Arepa Dominó 🎲
Caraotas negras y queso blanco: los dos colores del dominó. Un clásico de la cocina venezolana.
PEN 23.50
Arepa de Queso Llanero 🧀
Queso llanero derretido, suave y salado. Una arepa sencilla que resalta el sabor del mejor queso venezolano.
PEN 25.00
La Vegana 🌱
Arepa 100% Maíz hachas con Harina Pan, viene rellena con abundante Palta Fuerte , Tomate c/ aceite de oliva extra Virgen y orégano con Plátanos fritos preparada con ingredientes frescos y llenos de sabor.
PEN 27.90
Triple Veg 🌱
La combinación perfecta: Queso de Mano , Tomate y abundante Palta con aceite de Oliva extra virgen con orégano 🥑
PEN 28.50
Pabellón Vegetariano ⭐
Nuestra versión vegetariana del clásico: caraotas negras, queso blanco, plátano frito y abundante aguacate. ¡Espectacular!
PEN 28.90
El Gato ⭐
Arepa rellena con abundante queso de Mano, platanos fritos y Palta Sabor tradicional venezolano. 🥑
PEN 28.90
🍌 Plátano & Queso
Plátanos maduros recién fritos, dorados y dulces, irresistibles en cada bocado. Perfecto para acompañar tu Arepa!
PEN 11.90
🍌🧀 Plátano Frito con Queso
Plátanos maduros bien dorados con queso blanco rallado, una combinación clásica venezolana. Perfecto para acompañar tu Arepa!
PEN 17.90
Platano C/ Queso
Deliciosas tajadas de plátano maduro recién frito, servidas con generoso Queso de Mano . Dulce, cremoso y simplemente irresistible.
PEN 26.50
🍌🧀 Cachapa con Plátano y Queso
Cachapa de maíz dulce acompañada con abundante plátano frito dorado y queso de mano derretido. La mezcla perfecta entre dulce y salado.
PEN 37.90
🍌🧀 Empanada Plátano & Queso
Plátano maduro dorado con queso derretido, dentro de una empanada crujiente recién hecha. ⭐ Las más pedidas por nuestros clientes
PEN 23.90
Arepa de Queso Gouda 🧀
Arepa caliente con queso gouda rallado abundante, suave, cremoso y ligeramente derretido. Un clásico lleno de sabor.
PEN 24.50
Arepa de Queso Llanero 🧀
Arepa venezolana recién hecha rellena con abundante queso llanero, salado y lleno de sabor. Un clásico sencillo y delicioso.
PEN 24.50
Platano C/ Queso 🍌🧀
Deliciosas tajadas de plátano maduro recién frito, servidas con generoso Queso de Mano. Dulce, cremoso y simplemente irresistible.
PEN 26.50
Queso de Mano 🧀
Nuestra arepa rellena con abundante queso de mano suave y fresco. Un favorito tradicional venezolano.
PEN 24.50
Super Vegana ⭐
Caraotas negras cremosas con plátano frito, y aguacate. Sabores naturales que combinan perfecto.🌱
PEN 27.90
============= 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}
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
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}
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 ====================
=======
})(); -->
// ==================== CATEGORY FILTER ==================== ==================== 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');
});
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!
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!
¿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!
"¡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
"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
"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
"¡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
"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
"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.
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.
Finalizar Pedido
Resumen de tu Pedido
Total:S/ 0.00
¿Cómo Quieres Pedir?
o
Tus Datos
Por favor, inicia sesión o completa tus datos para continuar.
Método de Pago
Selecciona tu método de pago preferido:
Aceptamos pagos contra entrega en efectivo y mediante POS móvil (consultar disponibilidad).
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}
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}
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}
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
? ``
: `
`;
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}
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}
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}
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}
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}
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}
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
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');
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}
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}
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
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}
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
×
Tu carrito está vacío
¡Agrega algo delicioso del menú!
Subtotal
PEN 0.00
Total
PEN 0.00
Pedir por WhatsApp
`;
document.body.insertAdjacentHTML('beforeend', cartHTML);
}
// Create cart toggle button if it doesn't exist
if (!document.getElementById('cart-toggle-btn')) {
const cartToggleHTML = `
14
`;
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ú!
Subtotal
PEN 0.00
Total
PEN 0.00
Pedir por WhatsApp
Serás redirigido a WhatsApp
`;
document.body.insertAdjacentHTML('beforeend', cartHTML);
}
// Create cart toggle button if it doesn't exist
if (!document.getElementById('cart-toggle-btn')) {
const cartToggleHTML = `
14
`;
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}
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ú!
Subtotal
PEN 0.00
Total
PEN 0.00
Pedir por WhatsApp
`;
document.body.insertAdjacentHTML('beforeend', cartHTML);
}
// Create cart toggle button if it doesn't exist
if (!document.getElementById('cart-toggle-btn')) {
const cartToggleHTML = `
14
`;
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}
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
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}
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 ====================
=======