Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cart Refactoring #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions src/components/Cart/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export const CartSubTotalExcludeVat = ({ value, currency }) => {
<span className="font-semibold">Subtotal without VAT</span>
<span className="font-semibold">
<CurrencyBeforeValue
value={Math.trunc(value * 100) / 100}
value={value}
currency={currency}
/>
</span>
Expand All @@ -319,16 +319,16 @@ export const CartSubTotalIncludeVat = ({ grossValue, currency }) => {
)
}

export const CartVat = ({ value, taxPercentage, currency }) => {
export const CartVat = ({ taxAggregate, currency }) => {
return (
<>
<span>
VAT {taxPercentage}% of{' '}
<CurrencyBeforeValue value={value} currency={currency} />
VAT {taxAggregate.rate}% of{' '}
<CurrencyBeforeValue value={taxAggregate.taxable} currency={currency} />
</span>
<span>
<CurrencyBeforeValue
value={Math.trunc(value * (taxPercentage / 100) * 100) / 100}
value={taxAggregate.amount}
currency={currency}
/>
</span>
Expand Down Expand Up @@ -384,7 +384,7 @@ const CartGoCart = () => {
}

export const getShippingCost = (shippingMethod) => {
return shippingMethod != null ? shippingMethod?.fee : 0
return shippingMethod != null ? shippingMethod?.fees[0].amount : 0
}

export const CartActionPanel = ({ action }) => {
Expand Down Expand Up @@ -421,23 +421,29 @@ export const CartActionPanel = ({ action }) => {
</CartActionRow>
)}

{cartAccount &&
cartAccount?.taxAggregate &&
cartAccount?.taxAggregate.lines.length > 0 && (
cartAccount?.taxAggregate.lines.map((taxItem) => {
return (
<CartActionRow>
<LayoutBetween>
<CartVat
taxAggregate={taxItem}
currency={cartAccount?.currency}
/>
</LayoutBetween>
</CartActionRow>
)
})
)}

<CartActionRow>
<LayoutBetween>
{cartAccount &&
cartAccount?.taxAggregate &&
cartAccount?.taxAggregate.lines.length > 0 && (
<CartVat
value={cartAccount.totalPrice.amount}
taxPercentage={cartAccount?.taxAggregate.lines[0].rate}
currency={cartAccount?.currency}
/>
)}
</LayoutBetween>
<LayoutBetween>
{cartAccount?.subtotalAggregate &&
cartAccount?.subtotalAggregate.grossValue && (
<CartSubTotalIncludeVat
grossValue={cartAccount.totalPrice.amount + cartAccount.totalPrice.amount * cartAccount?.taxAggregate.lines[0].rate / 100 }
grossValue={cartAccount?.subtotalAggregate.grossValue}
currency={cartAccount.currency}
/>
)}
Expand All @@ -455,11 +461,7 @@ export const CartActionPanel = ({ action }) => {
<LayoutBetween>
{cartAccount.totalPrice && cartAccount.totalPrice.amount && (
<CartTotalPrice
totalValue={
cartAccount.totalPrice.amount +
+ cartAccount.totalPrice.amount * cartAccount?.taxAggregate.lines[0].rate / 100
+ getShippingCost(shippingMethod)
}
totalValue={cartAccount.totalPrice.amount}
currency={cartAccount.currency}
/>
)}
Expand Down