estructura inicial de carrito hecha

This commit is contained in:
2025-10-14 15:16:02 +02:00
parent 90376e61c8
commit a33ba3256b
11 changed files with 408 additions and 3 deletions

View File

@ -0,0 +1,28 @@
$(() => {
const badge = document.getElementById("cart-item-count");
if (!badge) return;
function updateCartCount() {
fetch("/cart/count")
.then(res => res.ok ? res.text() : "0")
.then(count => {
const n = parseInt(count || "0", 10);
if (isNaN(n) || n === 0) {
badge.classList.add("d-none");
} else {
badge.textContent = n;
badge.classList.remove("d-none");
}
})
.catch(() => badge.classList.add("d-none"));
}
// Actualizar al cargar
updateCartCount();
// Si quieres refrescar cada 60s:
setInterval(updateCartCount, 60000);
// generate a custom event to update the cart count from other scripts
document.addEventListener("update-cart", updateCartCount);
});