From 894f1337396c7fde5e0aa558d8d19b209bd99e9c Mon Sep 17 00:00:00 2001 From: Loan Laux Date: Tue, 10 Aug 2021 16:04:24 +0300 Subject: [PATCH] add support for displaying taxes Signed-off-by: Loan Laux --- .../checkout/CheckoutSidebarView/CheckoutSidebarView.tsx | 8 +++++++- framework/commerce/types/cart.ts | 2 ++ framework/reactioncommerce/utils/normalize.ts | 5 +++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/components/checkout/CheckoutSidebarView/CheckoutSidebarView.tsx b/components/checkout/CheckoutSidebarView/CheckoutSidebarView.tsx index 5060dac41..74c2e09b7 100644 --- a/components/checkout/CheckoutSidebarView/CheckoutSidebarView.tsx +++ b/components/checkout/CheckoutSidebarView/CheckoutSidebarView.tsx @@ -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 ( {
  • Taxes - Calculated at checkout + {data.taxes ? taxes : 'Calculated at checkout'}
  • Shipping diff --git a/framework/commerce/types/cart.ts b/framework/commerce/types/cart.ts index 9090fa502..97b120504 100644 --- a/framework/commerce/types/cart.ts +++ b/framework/commerce/types/cart.ts @@ -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 } /** diff --git a/framework/reactioncommerce/utils/normalize.ts b/framework/reactioncommerce/utils/normalize.ts index 8aec1717e..23a2e0446 100644 --- a/framework/reactioncommerce/utils/normalize.ts +++ b/framework/reactioncommerce/utils/normalize.ts @@ -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, } }