mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
See if cart is empty
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user