@@ -3,7 +3,7 @@ import { formatPrice } from '~/shared/utils';
3
3
import type { Store } from '~/types/store' ;
4
4
5
5
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 ) ;
7
7
8
8
export const isCartEmpty = ( cart : Store [ 'cart' ] ) => cart . products . length === 0 ;
9
9
@@ -66,7 +66,7 @@ export const getCartSavingTotalWithPromo = (cart: Store['cart']) => {
66
66
} ;
67
67
68
68
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 ) ;
70
70
71
71
export const getCartTotal = ( cart : Store [ 'cart' ] ) => {
72
72
const total = cartProductsWithQuantity ( cart ) . reduce (
@@ -93,7 +93,7 @@ export const getCartTotalWithDelivery = (cart: Store['cart']) => {
93
93
} ;
94
94
95
95
const cartProductsWithQuantity = ( cart : Store [ 'cart' ] ) =>
96
- cart . products . map ( ( cartProduct ) => ( {
96
+ ( cart . products || [ ] ) . map ( ( cartProduct ) => ( {
97
97
product : products . find ( ( p ) => p . id === cartProduct . id ) ,
98
98
quantity : cartProduct . quantity ,
99
99
} ) ) ;
0 commit comments