See if cart is empty

This commit is contained in:
Luis Alvarez
2020-10-05 01:05:04 -05:00
parent f8df1c1879
commit 2f35358942
3 changed files with 19 additions and 2 deletions

View File

@@ -23,6 +23,12 @@ export type Cart = {
base_amount: number
discount_amount: number
cart_amount: number
line_items: {
custom_items: any[]
digital_items: any[]
gift_certificates: any[]
psysical_items: any[]
}
// TODO: add missing fields
}

View File

@@ -18,8 +18,14 @@ export const CartProvider: FC = ({ children }) => {
export function useCart() {
const cart = useCommerceCart<Cart>()
// TODO: Do something to make this prop work
cart.isEmpty = true
Object.defineProperty(cart, 'isEmpty', {
get() {
return Object.values(cart.data?.line_items ?? {}).every(
(items) => !items.length
)
},
set: (x) => x,
})
return cart
}