mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 23:16: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,
|
productVariantId: item.variantId,
|
||||||
},
|
},
|
||||||
quantity: item.quantity,
|
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 * as Core from '@vercel/commerce/types/cart'
|
||||||
|
import { ProductVariant } from './product'
|
||||||
|
|
||||||
export * from '@vercel/commerce/types/cart'
|
export * from '@vercel/commerce/types/cart'
|
||||||
|
|
||||||
@ -8,10 +9,8 @@ export type Cart = Core.Cart & {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type CartItemBody = Core.CartItemBody & {
|
export type CartItemBody = Core.CartItemBody & {
|
||||||
price?: {
|
currencyCode?: string
|
||||||
amount: number
|
variant?: ProductVariant
|
||||||
currencyCode: string
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CartTypes = Core.CartTypes & {
|
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
|
return productVariants
|
||||||
}
|
}
|
||||||
|
|
||||||
const { sku, title, pricing = [], variantId } = variant ?? {}
|
const { pricing = [], variantId } = variant ?? {}
|
||||||
const variantPrice = pricing[0]?.price ?? pricing[0]?.minPrice ?? 0
|
const variantPrice = pricing[0]?.price ?? pricing[0]?.minPrice ?? 0
|
||||||
|
|
||||||
productVariants.push(<ProductVariant>{
|
productVariants.push({
|
||||||
id: variantId ?? '',
|
id: variantId ?? '',
|
||||||
name: title,
|
|
||||||
sku: sku ?? variantId,
|
|
||||||
price: variantPrice,
|
price: variantPrice,
|
||||||
listPrice: pricing[0]?.compareAtPrice?.amount ?? variantPrice,
|
|
||||||
requiresShipping: true,
|
|
||||||
options: [normalizeProductOption(variant)],
|
options: [normalizeProductOption(variant)],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -32,10 +32,8 @@ const ProductSidebar: FC<ProductSidebarProps> = ({ product, className }) => {
|
|||||||
await addItem({
|
await addItem({
|
||||||
productId: String(product.id),
|
productId: String(product.id),
|
||||||
variantId: String(variant ? variant.id : product.variants[0]?.id),
|
variantId: String(variant ? variant.id : product.variants[0]?.id),
|
||||||
price: {
|
variant,
|
||||||
amount: product.price.value,
|
|
||||||
currencyCode: String(product.price.currencyCode),
|
currencyCode: String(product.price.currencyCode),
|
||||||
},
|
|
||||||
})
|
})
|
||||||
openSidebar()
|
openSidebar()
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user