Skip to content

Commit a2dd8e1

Browse files
committed
add productWithQty.product check
1 parent 3058b0c commit a2dd8e1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/store/selectors.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export const getCartDiscountendTotal = (cart: Store['cart']) => {
1111
const total = cartProductsWithQuantity(cart).reduce(
1212
(total, productWithQty) =>
1313
total +
14-
productWithQty.product!.price.discounted.amount * productWithQty.quantity,
14+
(productWithQty.product?.price.discounted.amount || 0) *
15+
productWithQty.quantity,
1516
0
1617
);
1718
return formatPrice(total, 2);
@@ -21,7 +22,8 @@ export const getCartRegularTotal = (cart: Store['cart']) => {
2122
const total = cartProductsWithQuantity(cart).reduce(
2223
(total, productWithQty) =>
2324
total +
24-
productWithQty.product!.price.regular.amount * productWithQty.quantity,
25+
(productWithQty.product?.price.regular.amount || 0) *
26+
productWithQty.quantity,
2527
0
2628
);
2729
return formatPrice(total, 2);
@@ -31,8 +33,8 @@ export const getCartSavingTotal = (cart: Store['cart']) => {
3133
const total = cartProductsWithQuantity(cart).reduce(
3234
(total, productWithQty) =>
3335
total +
34-
(productWithQty.product!.price.regular.amount -
35-
productWithQty.product!.price.discounted.amount) *
36+
((productWithQty.product?.price.regular.amount || 0) -
37+
(productWithQty.product?.price.discounted.amount || 0)) *
3638
productWithQty.quantity,
3739
0
3840
);
@@ -43,7 +45,8 @@ export const getCartTotal = (cart: Store['cart'], promo: number) => {
4345
const total = cartProductsWithQuantity(cart).reduce(
4446
(total, productWithQty) =>
4547
total +
46-
productWithQty.product!.price.discounted.amount * productWithQty.quantity,
48+
(productWithQty.product?.price.discounted.amount || 0) *
49+
productWithQty.quantity,
4750
0
4851
);
4952
return formatPrice(total - promo + (cart.shippingOption === 1 ? 5 : 15), 2);

0 commit comments

Comments
 (0)