Panier | L'Heure Dorée

Livraison offerte dès 79€ d'achat • Retours sous 14 jours

Panier

Votre panier

0 article dans votre sélection

const FREE_SHIPPING_THRESHOLD = 79; const FLAT_SHIPPING_RATE = 6.90; const priceFormatter = new Intl.NumberFormat('fr-FR', { style: 'currency', currency: 'EUR' }); function formatPrice(value) { return priceFormatter.format(value || 0); } function normalizeCartItem(item) { const fallbackImage = 'https://placehold.co/240x240/F8F3EB/1F1A17?text=L%27Heure+Dor%C3%A9e'; return { ...item, price: Number(item.price) || 0, quantity: Math.max(1, Number(item.quantity) || 1), image: item.image || fallbackImage }; } function setCart(cart) { saveCart(cart); renderCart(); } function increaseQuantity(slug) { const cart = getCart().map(normalizeCartItem); const item = cart.find(i => i.slug === slug); if (!item) return; item.quantity += 1; setCart(cart); } function decreaseQuantity(slug) { let cart = getCart().map(normalizeCartItem); const item = cart.find(i => i.slug === slug); if (!item) return; item.quantity -= 1; if (item.quantity <= 0) { cart = cart.filter(i => i.slug !== slug); } setCart(cart); } function removeItem(slug) { const cart = getCart().filter(i => i.slug !== slug); setCart(cart); } function renderCart() { const cart = getCart().map(normalizeCartItem); const cartItems = document.getElementById('cartItems'); const cartEmptyState = document.getElementById('cartEmptyState'); const cartContent = document.getElementById('cartContent'); const cartHeaderCount = document.getElementById('cartHeaderCount'); const cartSubtotal = document.getElementById('cartSubtotal'); const cartShipping = document.getElementById('cartShipping'); const cartTotal = document.getElementById('cartTotal'); const freeShippingMessage = document.getElementById('freeShippingMessage'); const itemCount = cart.reduce((sum, item) => sum + item.quantity, 0); const subtotal = cart.reduce((sum, item) => sum + item.price * item.quantity, 0); const shipping = itemCount === 0 ? 0 : (subtotal >= FREE_SHIPPING_THRESHOLD ? 0 : FLAT_SHIPPING_RATE); const total = subtotal + shipping; cartHeaderCount.textContent = itemCount + ' ' + (itemCount > 1 ? 'articles dans votre sélection' : itemCount === 1 ? 'article dans votre sélection' : 'article dans votre sélection'); cartSubtotal.textContent = formatPrice(subtotal); cartShipping.textContent = shipping === 0 ? 'Offerte' : formatPrice(shipping); cartTotal.textContent = formatPrice(total); if (subtotal >= FREE_SHIPPING_THRESHOLD && itemCount > 0) { freeShippingMessage.textContent = 'Bonne nouvelle : votre commande bénéficie de la livraison offerte.'; } else if (itemCount > 0) { const remaining = FREE_SHIPPING_THRESHOLD - subtotal; freeShippingMessage.textContent = 'Ajoutez encore ' + formatPrice(remaining) + ' pour profiter de la livraison offerte.'; } else { freeShippingMessage.textContent = 'Livraison offerte dès 79€ d\'achat.'; } if (cart.length === 0) { cartEmptyState.classList.remove('hidden'); cartContent.classList.add('hidden'); cartItems.innerHTML = ''; return; } cartEmptyState.classList.add('hidden'); cartContent.classList.remove('hidden'); cartItems.innerHTML = cart.map(item => { const lineTotal = item.price * item.quantity; return `
${item.name}
${item.name}

Prix unitaire

${formatPrice(item.price)}