mirror of
https://github.com/vercel/commerce.git
synced 2025-03-31 17:25:53 +00:00
Updated normalizer for useData
This commit is contained in:
parent
61fa423673
commit
7cf1ace9fb
@ -92,11 +92,11 @@ const CartSidebarView: FC = () => {
|
|||||||
My Cart
|
My Cart
|
||||||
</h2>
|
</h2>
|
||||||
<ul className="py-6 space-y-6 sm:py-0 sm:space-y-0 sm:divide-y sm:divide-accents-3 border-t border-accents-3">
|
<ul className="py-6 space-y-6 sm:py-0 sm:space-y-0 sm:divide-y sm:divide-accents-3 border-t border-accents-3">
|
||||||
{data?.items?.map((item) => (
|
{data!.lineItems.map((item) => (
|
||||||
<CartItem
|
<CartItem
|
||||||
key={item.id}
|
key={item.id}
|
||||||
item={item}
|
item={item}
|
||||||
currencyCode={data?.currency.code!}
|
currencyCode={data!.currency.code}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -34,9 +34,7 @@ export function extendHook(
|
|||||||
descriptors: {
|
descriptors: {
|
||||||
isEmpty: {
|
isEmpty: {
|
||||||
get() {
|
get() {
|
||||||
return Object.values(response.data?.line_items ?? {}).every(
|
return (response.data?.lineItems.length ?? 0) <= 0
|
||||||
(items) => !items.length
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
},
|
},
|
||||||
|
@ -69,14 +69,30 @@ export function normalizeProduct(productNode: any): Product {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function normalizeCart(data: BigcommerceCart): Cart {
|
export function normalizeCart(data: BigcommerceCart): Cart {
|
||||||
const d: BaseCart = data && {
|
// const d: BaseCart = data && {
|
||||||
|
// id: data.id,
|
||||||
|
// customerId: String(data.customer_id),
|
||||||
|
// email: data.email,
|
||||||
|
// createdAt: data.created_time,
|
||||||
|
// currency: data.currency,
|
||||||
|
// taxesIncluded: data.tax_included,
|
||||||
|
// lineItems: data.line_items as any,
|
||||||
|
// lineItemsSubtotalPrice: data.base_amount,
|
||||||
|
// subtotalPrice: data.base_amount + data.discount_amount,
|
||||||
|
// totalPrice: data.cart_amount,
|
||||||
|
// discounts: data.discounts?.map((discount) => ({
|
||||||
|
// value: discount.discounted_amount,
|
||||||
|
// })),
|
||||||
|
// }
|
||||||
|
|
||||||
|
return {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
customerId: String(data.customer_id),
|
customerId: String(data.customer_id),
|
||||||
email: data.email,
|
email: data.email,
|
||||||
createdAt: data.created_time,
|
createdAt: data.created_time,
|
||||||
currency: data.currency,
|
currency: data.currency,
|
||||||
taxesIncluded: data.tax_included,
|
taxesIncluded: data.tax_included,
|
||||||
lineItems: data.line_items as any,
|
lineItems: data.line_items.physical_items.map(itemsToProducts) as any,
|
||||||
lineItemsSubtotalPrice: data.base_amount,
|
lineItemsSubtotalPrice: data.base_amount,
|
||||||
subtotalPrice: data.base_amount + data.discount_amount,
|
subtotalPrice: data.base_amount + data.discount_amount,
|
||||||
totalPrice: data.cart_amount,
|
totalPrice: data.cart_amount,
|
||||||
@ -85,14 +101,14 @@ export function normalizeCart(data: BigcommerceCart): Cart {
|
|||||||
})),
|
})),
|
||||||
}
|
}
|
||||||
|
|
||||||
return update(data as any, {
|
// return update(data as any, {
|
||||||
$auto: {
|
// $auto: {
|
||||||
items: { $set: data?.line_items?.physical_items?.map(itemsToProducts) },
|
// items: { $set: data?.line_items?.physical_items?.map(itemsToProducts) },
|
||||||
subTotal: { $set: data?.base_amount },
|
// subTotal: { $set: data?.base_amount },
|
||||||
total: { $set: data?.cart_amount },
|
// total: { $set: data?.cart_amount },
|
||||||
},
|
// },
|
||||||
$unset: ['created_time', 'coupons', 'line_items', 'email'],
|
// $unset: ['created_time', 'coupons', 'line_items', 'email'],
|
||||||
})
|
// })
|
||||||
}
|
}
|
||||||
|
|
||||||
function itemsToProducts(item: any): CartItem {
|
function itemsToProducts(item: any): CartItem {
|
||||||
|
2
framework/commerce/types.d.ts
vendored
2
framework/commerce/types.d.ts
vendored
@ -114,7 +114,7 @@ interface BaseCart {
|
|||||||
currency: { code: string }
|
currency: { code: string }
|
||||||
// Specifies if taxes are included in the line items.
|
// Specifies if taxes are included in the line items.
|
||||||
taxesIncluded: boolean
|
taxesIncluded: boolean
|
||||||
lineItems: Pick<Product, 'id' | 'name' | 'prices'> & CartItem[]
|
lineItems: BaseLineItem[]
|
||||||
// The sum of all the prices of all the items in the cart.
|
// The sum of all the prices of all the items in the cart.
|
||||||
// Duties, taxes, shipping and discounts excluded.
|
// Duties, taxes, shipping and discounts excluded.
|
||||||
lineItemsSubtotalPrice: number
|
lineItemsSubtotalPrice: number
|
||||||
|
Loading…
x
Reference in New Issue
Block a user