From c9fafd1c7801f037317b7a6bfe8b1143ed5057e1 Mon Sep 17 00:00:00 2001 From: Imugiii Date: Sat, 9 May 2026 09:18:56 +0000 Subject: [PATCH] feat(front): render menu composition breakdown in cart lines with supplement total --- src/public/borne/assets/js/page-cart.js | 52 ++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/src/public/borne/assets/js/page-cart.js b/src/public/borne/assets/js/page-cart.js index a4a7b79..5354b83 100644 --- a/src/public/borne/assets/js/page-cart.js +++ b/src/public/borne/assets/js/page-cart.js @@ -2,8 +2,14 @@ * page-cart.js — Shopping cart screen. * * Displays all cart lines with quantity controls and totals. + * Handles two item shapes: + * - Simple product: { id, type, libelle, prix_cents, quantite, image } + * - Composed menu: { ...above, composition: {...}, supplement_cents: number } * - * TVA: 10% (taux normal restauration, France 2024 — simplification MVPp). + * Menu lines render a composition breakdown beneath the product name. + * Simple product lines render as before (no composition block). + * + * TVA: 10% (taux normal restauration, France 2024 — simplification MVP). * TODO: verify exact applicable TVA rate with an accountant in P3. * The real rate depends on sur-place vs a-emporter, alcohol content, etc. * @@ -11,7 +17,7 @@ * requires prices shown to end-consumers to include all taxes. */ -import { getCart, removeFromCart, updateQuantity, getTotalCents, clearCart, formatPrice } from './state.js'; +import { getCart, removeFromCart, updateQuantity, getTotalCents, computeMenuLineCents, clearCart, formatPrice } from './state.js'; import { refreshCartBadge } from './nav.js'; /* TVA rate used for display breakdown only — stored prices are already TTC */ @@ -38,14 +44,16 @@ function renderCart() { return; } - emptyBlock.hidden = false; /* keep structure; toggle via class */ emptyBlock.hidden = true; summaryBlock.hidden = false; if (payBtn) payBtn.disabled = false; cartList.innerHTML = ''; items.forEach((item, index) => { - const lineTotalCents = item.prix_cents * item.quantite; + const isMenu = item.type === 'menu'; + const lineTotalCents = isMenu + ? computeMenuLineCents(item) + : item.prix_cents * item.quantite; const row = document.createElement('li'); row.className = 'cart-line'; @@ -60,7 +68,8 @@ function renderCart() { >
${item.libelle} - ${formatPrice(item.prix_cents)} / unite + ${formatPrice(item.prix_cents)} / unite${isMenu && (item.supplement_cents ?? 0) > 0 ? ` + ${formatPrice(item.supplement_cents)} suppl.` : ''} + ${isMenu && item.composition ? renderCompositionBlock(item) : ''}