Skip to content

Commit 0d77fa5

Browse files
committed
fix array issue
1 parent cfb9203 commit 0d77fa5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/store/selectors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { formatPrice } from '~/shared/utils';
33
import type { Store } from '~/types/store';
44

55
export const getCartQuantity = (cart: Store['cart']) =>
6-
cart.products.reduce((total, item) => total + item.quantity, 0);
6+
(cart.products || []).reduce((total, item) => total + item.quantity, 0);
77

88
export const isCartEmpty = (cart: Store['cart']) => cart.products.length === 0;
99

@@ -66,7 +66,7 @@ export const getCartSavingTotalWithPromo = (cart: Store['cart']) => {
6666
};
6767

6868
const getPromoTotal = (cart: Store['cart']) =>
69-
cart.promoCodes.reduce((total, promo) => total + promo.value, 0);
69+
(cart.promoCodes || []).reduce((total, promo) => total + promo.value, 0);
7070

7171
export const getCartTotal = (cart: Store['cart']) => {
7272
const total = cartProductsWithQuantity(cart).reduce(
@@ -93,7 +93,7 @@ export const getCartTotalWithDelivery = (cart: Store['cart']) => {
9393
};
9494

9595
const cartProductsWithQuantity = (cart: Store['cart']) =>
96-
cart.products.map((cartProduct) => ({
96+
(cart.products || []).map((cartProduct) => ({
9797
product: products.find((p) => p.id === cartProduct.id),
9898
quantity: cartProduct.quantity,
9999
}));

0 commit comments

Comments
 (0)