From 387ba19802910f5719d6acfadd25d756bca6bf2d Mon Sep 17 00:00:00 2001 From: DanielS Date: Thu, 9 Jul 2026 23:33:16 +0200 Subject: [PATCH] fix: loop and render all basket items in wizard summary screen --- shop/components/order-wizard.tsx | 143 +++++++++++++++++-------------- 1 file changed, 78 insertions(+), 65 deletions(-) diff --git a/shop/components/order-wizard.tsx b/shop/components/order-wizard.tsx index 9c85f33..feef170 100644 --- a/shop/components/order-wizard.tsx +++ b/shop/components/order-wizard.tsx @@ -622,6 +622,12 @@ export function OrderWizard({ } + const finalItemsToShow = basketItems.length > 0 + ? basketItems + : (allCategoriesFilled && productValidationErrors.length === 0 + ? [{ deviceName: deviceName || 'Kasse 1', selections, moduleQuantities, billingInterval: selectedBillingInterval }] + : []); + return (
{/* Progress Stepper */} @@ -1426,72 +1432,79 @@ export function OrderWizard({ -
- {visibleCategories.map(cat => { - const sel = selections[cat.id] - const selectedProds: Product[] = [] - if (cat.allow_multiselect && sel?.productIds) { - sel.productIds.forEach(pId => { - const p = products.find(prod => prod.id === pId) - if (p) selectedProds.push(p) - }) - } else if (sel?.productId) { - const p = products.find(prod => prod.id === sel.productId) - if (p) selectedProds.push(p) - } - - if (selectedProds.length === 0) return null - - // Sort selected products by price to determine which ones are free - const sortedProds = [...selectedProds].sort((a, b) => a.base_price - b.base_price) - const freeLimit = cat.allow_multiselect ? cat.free_items_limit : 0 - - return ( -
-
- - {cat.name} -
- {sortedProds.map((prod, idx) => { - const isFree = idx < freeLimit - const actualPrice = isFree ? 0 : prod.base_price - const catTotal = - Number(actualPrice) + - (sel?.moduleIds?.reduce((acc, mId) => { - const mod = prod.modules?.find(m => m.id === mId) - const qty = moduleQuantities[mId] || 1 - return acc + (Number(mod?.price ?? 0) * qty) - }, 0) || 0) - - return ( -
-
- - {prod.name} {isFree && (Frei)} - - - {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(catTotal)} - {' '}{billingLabel(prod.billing_interval)} - -
- {sel?.moduleIds && sel.moduleIds.length > 0 && ( -

- Module: {sel.moduleIds - .map(id => { - const mod = prod.modules?.find(m => m.id === id) - const qty = moduleQuantities[id] || 1 - return mod ? `${mod.name}${mod.has_quantity ? ` (x${qty})` : ''}` : '' - }) - .filter(Boolean) - .join(', ')} -

- )} -
- ) - })} +
+ {finalItemsToShow.map((item, itemIdx) => ( +
+
+ Gerät: {item.deviceName} + {item.billingInterval === 'one_time' ? 'Kauf' : 'Abo'}
- ) - })} + + {visibleCategories.map(cat => { + const sel = item.selections[cat.id] + const selectedProds: Product[] = [] + if (cat.allow_multiselect && sel?.productIds) { + sel.productIds.forEach(pId => { + const p = products.find(prod => prod.id === pId) + if (p) selectedProds.push(p) + }) + } else if (sel?.productId) { + const p = products.find(prod => prod.id === sel.productId) + if (p) selectedProds.push(p) + } + + if (selectedProds.length === 0) return null + + const sortedProds = [...selectedProds].sort((a, b) => a.base_price - b.base_price) + const freeLimit = cat.allow_multiselect ? cat.free_items_limit : 0 + + return ( +
+
+ + {cat.name} +
+ {sortedProds.map((prod, idx) => { + const isFree = idx < freeLimit + const actualPrice = isFree ? 0 : prod.base_price + const catTotal = + Number(actualPrice) + + (sel?.moduleIds?.reduce((acc, mId) => { + const mod = prod.modules?.find(m => m.id === mId) + const qty = item.moduleQuantities[mId] || 1 + return acc + (Number(mod?.price ?? 0) * qty) + }, 0) || 0) + + return ( +
+
+ + {prod.name} {isFree && (Frei)} + + + {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(catTotal)} + +
+ {sel?.moduleIds && sel.moduleIds.length > 0 && ( +

+ Module: {sel.moduleIds + .map(id => { + const mod = prod.modules?.find(m => m.id === id) + const qty = item.moduleQuantities[id] || 1 + return mod ? `${mod.name}${mod.has_quantity ? ` (x${qty})` : ''}` : '' + }) + .filter(Boolean) + .join(', ')} +

+ )} +
+ ) + })} +
+ ) + })} +
+ ))}
{selectedEndCustomer ? (