From 017218c155896898d0ddcd6803c1bffccb2ae1af Mon Sep 17 00:00:00 2001 From: okbel Date: Tue, 19 Jan 2021 11:07:40 -0300 Subject: [PATCH] Progress --- components/cart/CartSidebarView/CartSidebarView.tsx | 5 +++-- framework/bigcommerce/lib/normalize.ts | 8 +++++--- framework/types.d.ts | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/components/cart/CartSidebarView/CartSidebarView.tsx b/components/cart/CartSidebarView/CartSidebarView.tsx index 19c6964d7..dd3b62f29 100644 --- a/components/cart/CartSidebarView/CartSidebarView.tsx +++ b/components/cart/CartSidebarView/CartSidebarView.tsx @@ -15,13 +15,14 @@ const CartSidebarView: FC = () => { const { price: subTotal } = usePrice( data && { - amount: data.base_amount, + amount: data.subTotal, currencyCode: data.currency?.code || 'USD', } ) + const { price: total } = usePrice( data && { - amount: data.cart_amount, + amount: data.total, currencyCode: data.currency?.code || 'USD', } ) diff --git a/framework/bigcommerce/lib/normalize.ts b/framework/bigcommerce/lib/normalize.ts index cd7763c6e..35c8d48b2 100644 --- a/framework/bigcommerce/lib/normalize.ts +++ b/framework/bigcommerce/lib/normalize.ts @@ -75,10 +75,12 @@ export function normalizeProduct(productNode: any): Product { }) } -export function normalizeCart(cart: any): Cart { - return update(cart, { +export function normalizeCart(data: any): Cart { + return update(data, { $auto: { - products: { $set: cart?.line_items?.physical_items?.map(itemsToProducts)} + products: { $set: data?.line_items?.physical_items?.map(itemsToProducts)}, + subTotal: { $set: data.base_amount }, + total: { $set: data.cart_amount } }, $unset: ['created_time', 'coupons', 'line_items'] }) diff --git a/framework/types.d.ts b/framework/types.d.ts index 9ee622c4b..31d5aedf3 100644 --- a/framework/types.d.ts +++ b/framework/types.d.ts @@ -49,8 +49,9 @@ interface Cart extends Entity { id: string | undefined currency: { code: string } taxIncluded?: boolean - totalAmmount: number | string products: Pick & CartItem[] + subTotal: number | string + total: number | string } interface CartItem extends Entity {