forked from crowetic/commerce
See if cart is empty
This commit is contained in:
parent
f8df1c1879
commit
2f35358942
@ -3,9 +3,14 @@ import { UserNav } from '@components/core'
|
||||
import { Button } from '@components/ui'
|
||||
import { Trash, Cross } from '@components/icon'
|
||||
import { useUI } from '@components/ui/context'
|
||||
import { useCart } from '@lib/bigcommerce/cart'
|
||||
|
||||
const CartSidebarView: FC = () => {
|
||||
const { data, isEmpty } = useCart()
|
||||
const { closeSidebar } = useUI()
|
||||
|
||||
console.log('CART', data, isEmpty)
|
||||
|
||||
return (
|
||||
<>
|
||||
<header className="px-4 py-6 sm:px-6 border-b border-gray-200">
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user