add support for displaying taxes

Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
Loan Laux 2021-08-10 16:04:24 +03:00
parent 2943168803
commit 894f133739
No known key found for this signature in database
GPG Key ID: AF9E9BD6548AD52E
3 changed files with 12 additions and 3 deletions

View File

@ -26,6 +26,12 @@ const CheckoutSidebarView: FC = () => {
currencyCode: data.currency.code,
}
)
const { price: taxes } = usePrice(
data && {
amount: Number(data.taxes),
currencyCode: data.currency.code,
}
)
return (
<SidebarLayout
@ -68,7 +74,7 @@ const CheckoutSidebarView: FC = () => {
</li>
<li className="flex justify-between py-1">
<span>Taxes</span>
<span>Calculated at checkout</span>
<span>{data.taxes ? taxes : 'Calculated at checkout'}</span>
</li>
<li className="flex justify-between py-1">
<span>Shipping</span>

View File

@ -81,6 +81,8 @@ export type Cart = {
totalPrice: number
// Discounts that have been applied on the cart.
discounts?: Discount[]
// The total for taxes
taxes?: number
}
/**

View File

@ -203,8 +203,8 @@ export function normalizeProduct(productNode: CatalogItemProduct): Product {
export function normalizeCart(cart: ReactionCart): Cart {
return {
id: cart._id,
customerId: '',
email: '',
customerId: cart.account?._id ?? '',
email: cart.account?.emailRecords[0].address ?? '',
createdAt: cart.createdAt,
currency: {
code: cart.checkout?.summary?.total?.currency.code ?? '',
@ -218,6 +218,7 @@ export function normalizeCart(cart: ReactionCart): Cart {
subtotalPrice: +(cart.checkout?.summary?.itemTotal?.amount ?? 0),
totalPrice: cart.checkout?.summary?.total?.amount ?? 0,
discounts: [],
taxes: cart.checkout?.summary?.taxTotal?.amount,
}
}