mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-24 01:30:21 +00:00
estructura inicial de carrito hecha
This commit is contained in:
@ -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);
|
||||
});
|
||||
Reference in New Issue
Block a user