From e5f3952887a9f32b7a4fee90edd1b46488b31c49 Mon Sep 17 00:00:00 2001 From: lytrankieio123 Date: Thu, 21 Oct 2021 14:13:07 +0700 Subject: [PATCH] :bug: bug: shippingLine undefined :%s --- framework/commerce/types/cart.ts | 2 +- framework/vendure/api/operations/get-product.ts | 2 +- framework/vendure/utils/normalize.ts | 8 ++++---- .../modules/checkout/CheckoutBill/CheckoutBill.tsx | 2 +- .../modules/checkout/CheckoutInfo/CheckoutInfo.tsx | 6 ++++-- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/framework/commerce/types/cart.ts b/framework/commerce/types/cart.ts index e0d56b3bb..9192436d0 100644 --- a/framework/commerce/types/cart.ts +++ b/framework/commerce/types/cart.ts @@ -122,7 +122,7 @@ export type CartCheckout = { // Discounts that have been applied on the cart. discounts?: Discount[] totalDiscount: number - shippingLine: { + shippingLine?: { priceWithTax: number shippingMethod: ShippingMethod } diff --git a/framework/vendure/api/operations/get-product.ts b/framework/vendure/api/operations/get-product.ts index 66f798ee1..c16041468 100644 --- a/framework/vendure/api/operations/get-product.ts +++ b/framework/vendure/api/operations/get-product.ts @@ -2,7 +2,7 @@ import { Product } from '@commerce/types/product' import { OperationContext } from '@commerce/api/operations' import { Provider, VendureConfig } from '../' import { GetProductQuery } from '../../schema' -import { getProductQuery, getProductDetailQuery } from '../../utils/queries/get-product-query' +import { getProductQuery } from '../../utils/queries/get-product-query' export default function getProductOperation({ commerce, diff --git a/framework/vendure/utils/normalize.ts b/framework/vendure/utils/normalize.ts index 7a2ab0d24..63444b45d 100644 --- a/framework/vendure/utils/normalize.ts +++ b/framework/vendure/utils/normalize.ts @@ -94,10 +94,10 @@ export function normalizeCartForCheckout(order: CartFragment): CartCheckout { countryCode: order.shippingAddress?.countryCode || '', phoneNumber: order.shippingAddress?.phoneNumber || '', }, - shippingLine: { - priceWithTax: order.shippingLines[0].priceWithTax / 100, - shippingMethod: order.shippingLines[0].shippingMethod as ShippingMethod - }, + shippingLine: order.shippingLines[0] ? { + priceWithTax: order.shippingLines[0]?.priceWithTax / 100, + shippingMethod: order.shippingLines[0]?.shippingMethod as ShippingMethod + }: undefined, totalDiscount: order.discounts?.reduce((total, item) => total + item.amountWithTax, 0) / 100 || 0, discounts: order.discounts.map(item => { return { value: item.amountWithTax, description: item.description } diff --git a/src/components/modules/checkout/CheckoutBill/CheckoutBill.tsx b/src/components/modules/checkout/CheckoutBill/CheckoutBill.tsx index 4dae3484b..3e3910c90 100644 --- a/src/components/modules/checkout/CheckoutBill/CheckoutBill.tsx +++ b/src/components/modules/checkout/CheckoutBill/CheckoutBill.tsx @@ -49,7 +49,7 @@ const CheckoutBill = ({ data }: CheckoutBillProps) => {
Shipping -
{data?.shippingLine.priceWithTax || 0} {data?.currency?.code}
+
{data?.shippingLine?.priceWithTax || 0} {data?.currency?.code}
Estimated Total diff --git a/src/components/modules/checkout/CheckoutInfo/CheckoutInfo.tsx b/src/components/modules/checkout/CheckoutInfo/CheckoutInfo.tsx index e96d3bda1..32cfec5fd 100644 --- a/src/components/modules/checkout/CheckoutInfo/CheckoutInfo.tsx +++ b/src/components/modules/checkout/CheckoutInfo/CheckoutInfo.tsx @@ -91,8 +91,10 @@ const CheckoutInfo = ({ onViewCart, currency = "" }: CheckoutInfoProps) => { } return '' case CheckoutStep.ShippingMethodInfo: - console.log('oder here: ', order?.shippingLine) - return `${order?.shippingLine.shippingMethod.name}, ${order?.shippingLine.priceWithTax ? `${order?.shippingLine.priceWithTax} ${currency}`: 'Free'}` || '' + if (order?.shippingLine) { + return `${order?.shippingLine.shippingMethod.name}, ${order?.shippingLine.priceWithTax ? `${order?.shippingLine.priceWithTax} ${currency}` : 'Free'}` || '' + } + return '' default: return "" }