Skip to content

Commit 36d9a00

Browse files
authored
Cart total/tax fixes (#961)
1 parent 6aeb2b3 commit 36d9a00

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

resources/js/stores/useCart.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ export const cart = computed({
184184
refresh()
185185
}
186186

187-
cartStorage.value.fixedProductTaxes = fixedProductTaxes
188-
cartStorage.value.taxTotal = taxTotal
187+
cartStorage.value.fixedProductTaxes = fixedProductTaxes(cartStorage.value)
188+
cartStorage.value.taxTotal = taxTotal(cartStorage.value)
189189

190190
return cartStorage.value
191191
},
@@ -254,22 +254,22 @@ export const cart = computed({
254254
},
255255
})
256256

257-
export const fixedProductTaxes = computed(() => {
257+
export const fixedProductTaxes = (cart) => {
258258
let taxes = {}
259259
// Note: Magento does internal rounding before multiplying by the quantity, so we actually don't lose any precision here by using the rounded tax amount.
260-
cart.value?.items?.forEach((item) =>
260+
cart?.items?.forEach((item) =>
261261
item.prices?.fixed_product_taxes?.forEach((tax) => (taxes[tax.label] = (taxes[tax.label] ?? 0) + tax.amount.value * item.quantity)),
262262
)
263263
return taxes
264-
})
264+
}
265265

266-
export const taxTotal = computed(() => {
267-
if (!cart?.value?.prices?.applied_taxes?.length) {
266+
export const taxTotal = (cart) => {
267+
if (!cart?.prices?.applied_taxes?.length) {
268268
return 0
269269
}
270270

271-
return cart.value.prices.applied_taxes.reduce((sum, tax) => sum + tax.amount.value, 0)
272-
})
271+
return cart.prices.applied_taxes.reduce((sum, tax) => sum + tax.amount.value, 0)
272+
}
273273

274274
watch(mask, refresh)
275275
if (cartStorage.value?.id && !mask.value) {

resources/views/cart/sidebar.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</div>
2424
</template>
2525

26-
<template v-if="cart.fixedProductTaxes?.value">
26+
<template v-if="cart.fixedProductTaxes">
2727
<div v-for="value, label in cart.fixed_product_taxes">
2828
<dt>@{{ label }}</dt>
2929
<dd>@{{ value | price }}</dd>
@@ -40,7 +40,7 @@
4040
<div class="border-t pt-3 mt-3 font-bold">
4141
<dt>@lang('Total')</dt>
4242
<dd v-if="showTax">@{{ cart.prices.grand_total.value | price }}</dd>
43-
<dd v-else>@{{ cart.prices.grand_total.value - cart.taxTotal.value | price }}</dd>
43+
<dd v-else>@{{ cart.prices.grand_total.value - cart.taxTotal | price }}</dd>
4444
</div>
4545
</x-rapidez::summary>
4646

0 commit comments

Comments
 (0)