mirror of
https://github.com/vercel/commerce.git
synced 2025-06-29 18:01:21 +00:00
31 lines
812 B
TypeScript
31 lines
812 B
TypeScript
import useBigCommerceCart from '@bigcommerce/storefront-data-hooks/cart/use-cart'
|
|
import useBigCommercePrice from '@bigcommerce/storefront-data-hooks/use-price'
|
|
|
|
export const useCart = () => {
|
|
const { data, error, isEmpty } = useBigCommerceCart()
|
|
const items = data?.line_items.physical_items ?? []
|
|
|
|
const { price: subtotal } = useBigCommercePrice(
|
|
data && {
|
|
amount: data.base_amount,
|
|
currencyCode: data.currency.code,
|
|
}
|
|
)
|
|
const { price: total } = useBigCommercePrice(
|
|
data && {
|
|
amount: data.cart_amount,
|
|
currencyCode: data.currency.code,
|
|
}
|
|
)
|
|
|
|
return {
|
|
items: data?.line_items.physical_items ?? [],
|
|
isLoading: data === undefined,
|
|
isError: error,
|
|
isEmpty: isEmpty && data === null,
|
|
subtotal,
|
|
total,
|
|
currency: data?.currency,
|
|
}
|
|
}
|