shipping methods details
This commit is contained in:
parent
174439cc3b
commit
82adc37850
1 changed files with 10 additions and 8 deletions
|
@ -36,6 +36,7 @@
|
||||||
});
|
});
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
shippingOptions = data.shipping_options;
|
shippingOptions = data.shipping_options;
|
||||||
|
console.log(shippingOptions);
|
||||||
|
|
||||||
// If there's only one option, select it automatically
|
// If there's only one option, select it automatically
|
||||||
if (shippingOptions.length === 1) {
|
if (shippingOptions.length === 1) {
|
||||||
|
@ -66,9 +67,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateTotal(items: any[]) {
|
function calculateTotal(items: any[]) {
|
||||||
return items.reduce((sum, item) =>
|
const itemsTotal = items.reduce((sum, item) =>
|
||||||
sum + (item.unit_price * item.quantity), 0
|
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) {
|
function getCurrencySymbol(currency_code: string) {
|
||||||
|
@ -135,13 +142,8 @@
|
||||||
/>
|
/>
|
||||||
<div class="flex-1">
|
<div class="flex-1">
|
||||||
<p class="text-sm font-medium">{option.name}</p>
|
<p class="text-sm font-medium">{option.name}</p>
|
||||||
{#if option.data}
|
<p class="text-xs text-base-content/70">{option.amount} {currencySymbol}</p>
|
||||||
<p class="text-xs text-base-content/70">{option.data.id}</p>
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
<!-- {#if option.insufficient_inventory}
|
|
||||||
<span class="badge badge-warning badge-sm">Limited Stock</span>
|
|
||||||
{/if} -->
|
|
||||||
</label>
|
</label>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue