From 82adc378500db7adc501513a4fe43561523e2efe Mon Sep 17 00:00:00 2001 From: nomad Date: Fri, 13 Jun 2025 20:10:26 +0300 Subject: [PATCH] shipping methods details --- src/lib/components/checkout.svelte | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/lib/components/checkout.svelte b/src/lib/components/checkout.svelte index fa9f140..86251e7 100644 --- a/src/lib/components/checkout.svelte +++ b/src/lib/components/checkout.svelte @@ -36,6 +36,7 @@ }); const data = await response.json(); shippingOptions = data.shipping_options; + console.log(shippingOptions); // If there's only one option, select it automatically if (shippingOptions.length === 1) { @@ -66,9 +67,15 @@ } function calculateTotal(items: any[]) { - return items.reduce((sum, item) => + const itemsTotal = items.reduce((sum, item) => sum + (item.unit_price * item.quantity), 0 - ).toFixed(2); + ); + + const shippingCost = selectedShippingOption + ? shippingOptions.find(opt => opt.id === selectedShippingOption)?.amount || 0 + : 0; + + return (itemsTotal + shippingCost).toFixed(2); } function getCurrencySymbol(currency_code: string) { @@ -135,13 +142,8 @@ />

{option.name}

- {#if option.data} -

{option.data.id}

- {/if} +

{option.amount} {currencySymbol}

- {/each}