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 { Button } from '@components/ui'
|
||||||
import { Trash, Cross } from '@components/icon'
|
import { Trash, Cross } from '@components/icon'
|
||||||
import { useUI } from '@components/ui/context'
|
import { useUI } from '@components/ui/context'
|
||||||
|
import { useCart } from '@lib/bigcommerce/cart'
|
||||||
|
|
||||||
const CartSidebarView: FC = () => {
|
const CartSidebarView: FC = () => {
|
||||||
|
const { data, isEmpty } = useCart()
|
||||||
const { closeSidebar } = useUI()
|
const { closeSidebar } = useUI()
|
||||||
|
|
||||||
|
console.log('CART', data, isEmpty)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<header className="px-4 py-6 sm:px-6 border-b border-gray-200">
|
<header className="px-4 py-6 sm:px-6 border-b border-gray-200">
|
||||||
|
@ -23,6 +23,12 @@ export type Cart = {
|
|||||||
base_amount: number
|
base_amount: number
|
||||||
discount_amount: number
|
discount_amount: number
|
||||||
cart_amount: number
|
cart_amount: number
|
||||||
|
line_items: {
|
||||||
|
custom_items: any[]
|
||||||
|
digital_items: any[]
|
||||||
|
gift_certificates: any[]
|
||||||
|
psysical_items: any[]
|
||||||
|
}
|
||||||
// TODO: add missing fields
|
// TODO: add missing fields
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,14 @@ export const CartProvider: FC = ({ children }) => {
|
|||||||
export function useCart() {
|
export function useCart() {
|
||||||
const cart = useCommerceCart<Cart>()
|
const cart = useCommerceCart<Cart>()
|
||||||
|
|
||||||
// TODO: Do something to make this prop work
|
Object.defineProperty(cart, 'isEmpty', {
|
||||||
cart.isEmpty = true
|
get() {
|
||||||
|
return Object.values(cart.data?.line_items ?? {}).every(
|
||||||
|
(items) => !items.length
|
||||||
|
)
|
||||||
|
},
|
||||||
|
set: (x) => x,
|
||||||
|
})
|
||||||
|
|
||||||
return cart
|
return cart
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user