mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-19 15:20:20 +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);
|
||||
});
|
||||
@ -39,6 +39,10 @@
|
||||
<th:block layout:fragment="pagejs" />
|
||||
<script th:src="@{/assets/js/app.js}"></script>
|
||||
<script th:src="@{/assets/js/pages/imprimelibros/languageBundle.js}"></script>
|
||||
<th:block th:if="${#authorization.expression('isAuthenticated()')}">
|
||||
<script src="/assets/js/pages/imprimelibros/cart-badge.js"></script>
|
||||
</th:block>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -54,8 +54,8 @@
|
||||
</a>
|
||||
|
||||
<!-- item-->
|
||||
<a href="javascript:void(0);" class="dropdown-item notify-item language py-2" data-lang="en-GB"
|
||||
title="English">
|
||||
<a href="javascript:void(0);" class="dropdown-item notify-item language py-2"
|
||||
data-lang="en-GB" title="English">
|
||||
<img src="/assets/images/flags/gb.svg" alt="user-image" class="me-2 rounded"
|
||||
height="18">
|
||||
<span class="align-middle">English</span>
|
||||
@ -64,6 +64,19 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div th:if="${#authorization.expression('isAuthenticated()')}"
|
||||
class="ms-1 header-item d-none d-sm-flex">
|
||||
<button type="button" id="btn_cart"
|
||||
class="btn btn-icon btn-topbar material-shadow-none btn-ghost-secondary rounded-circle light-dark-mode">
|
||||
<i class="bx bx-cart fs-22"></i>
|
||||
<span id="cart-item-count"
|
||||
class="position-absolute topbar-badge cartitem-badge fs-10 translate-middle badge rounded-pill bg-info d-none">
|
||||
0
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div th:if="${#authorization.expression('isAuthenticated()')}">
|
||||
<div class="dropdown ms-sm-3 header-item topbar-user">
|
||||
@ -92,7 +105,8 @@
|
||||
<a class="dropdown-item" href="#"
|
||||
onclick="document.getElementById('logoutForm').submit(); return false;">
|
||||
<i class="mdi mdi-logout text-muted fs-16 align-middle me-1"></i>
|
||||
<span class="align-middle" data-key="t-logout" th:text="#{app.logout}">Cerrar sesión</span>
|
||||
<span class="align-middle" data-key="t-logout" th:text="#{app.logout}">Cerrar
|
||||
sesión</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user