mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 15:06:59 +00:00
Update add multiple variant items logic
Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
This commit is contained in:
parent
dd3efaa301
commit
4c4f49c676
@ -29,7 +29,10 @@ const addItem: CartEndpoint['handlers']['addItem'] = async ({
|
||||
productVariantId: item.variantId,
|
||||
},
|
||||
quantity: item.quantity,
|
||||
price: item.price,
|
||||
price: {
|
||||
amount: item.variant?.price,
|
||||
currencyCode: item.currencyCode,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -1,4 +1,5 @@
|
||||
import * as Core from '@vercel/commerce/types/cart'
|
||||
import { ProductVariant } from './product'
|
||||
|
||||
export * from '@vercel/commerce/types/cart'
|
||||
|
||||
@ -8,10 +9,8 @@ export type Cart = Core.Cart & {
|
||||
}
|
||||
|
||||
export type CartItemBody = Core.CartItemBody & {
|
||||
price?: {
|
||||
amount: number
|
||||
currencyCode: string
|
||||
}
|
||||
currencyCode?: string
|
||||
variant?: ProductVariant
|
||||
}
|
||||
|
||||
export type CartTypes = Core.CartTypes & {
|
||||
|
@ -1 +1,11 @@
|
||||
export * from '@vercel/commerce/types/product'
|
||||
import * as Core from '@vercel/commerce/types/product'
|
||||
|
||||
export type Product = Core.Product
|
||||
|
||||
export type ProductVariant = Core.ProductVariant & {
|
||||
price?: number
|
||||
}
|
||||
|
||||
export type ProductOption = Core.ProductOption
|
||||
|
||||
export type ProductOptionValues = Core.ProductOptionValues
|
||||
|
@ -154,16 +154,12 @@ const normalizeProductVariants = (
|
||||
return productVariants
|
||||
}
|
||||
|
||||
const { sku, title, pricing = [], variantId } = variant ?? {}
|
||||
const { pricing = [], variantId } = variant ?? {}
|
||||
const variantPrice = pricing[0]?.price ?? pricing[0]?.minPrice ?? 0
|
||||
|
||||
productVariants.push(<ProductVariant>{
|
||||
productVariants.push({
|
||||
id: variantId ?? '',
|
||||
name: title,
|
||||
sku: sku ?? variantId,
|
||||
price: variantPrice,
|
||||
listPrice: pricing[0]?.compareAtPrice?.amount ?? variantPrice,
|
||||
requiresShipping: true,
|
||||
options: [normalizeProductOption(variant)],
|
||||
})
|
||||
|
||||
|
@ -32,10 +32,8 @@ const ProductSidebar: FC<ProductSidebarProps> = ({ product, className }) => {
|
||||
await addItem({
|
||||
productId: String(product.id),
|
||||
variantId: String(variant ? variant.id : product.variants[0]?.id),
|
||||
price: {
|
||||
amount: product.price.value,
|
||||
currencyCode: String(product.price.currencyCode),
|
||||
},
|
||||
variant,
|
||||
currencyCode: String(product.price.currencyCode),
|
||||
})
|
||||
openSidebar()
|
||||
setLoading(false)
|
||||
|
Loading…
x
Reference in New Issue
Block a user