mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 21:51:21 +00:00
Mapped options to variants
This commit is contained in:
parent
e3a9fd6c51
commit
f7796b9683
@ -9,9 +9,7 @@ export function getVariant(product: Product, opts: SelectedOptions) {
|
||||
option.__typename === 'MultipleChoiceOption' &&
|
||||
option.displayName.toLowerCase() === key.toLowerCase()
|
||||
) {
|
||||
return option.values.find((v) => {
|
||||
return v.label.toLowerCase() === value
|
||||
})
|
||||
return option.values.find((v) => v.label.toLowerCase() === value)
|
||||
}
|
||||
})
|
||||
)
|
||||
|
@ -35,7 +35,6 @@ const normalizeProductOptions = (options: ProductVariant[]) => {
|
||||
|
||||
return {
|
||||
__typename: 'MultipleChoiceOption',
|
||||
id: 123,
|
||||
// next-commerce can only display labels for options with displayName 'size', or colors
|
||||
displayName: displayName?.toLowerCase().includes('size')
|
||||
? 'size'
|
||||
@ -48,7 +47,8 @@ const normalizeProductOptions = (options: ProductVariant[]) => {
|
||||
}
|
||||
|
||||
const normalizeProductVariants = (variants: ProductVariant[]) =>
|
||||
variants?.map(({ id, sku, name, pricing }) => {
|
||||
variants?.map((variant) => {
|
||||
const { id, sku, name, pricing } = variant
|
||||
const price = pricing?.price?.net && money(pricing.price.net)?.value
|
||||
|
||||
return {
|
||||
@ -58,7 +58,7 @@ const normalizeProductVariants = (variants: ProductVariant[]) =>
|
||||
price,
|
||||
listPrice: price,
|
||||
requiresShipping: true,
|
||||
options: normalizeProductOptions(variants),
|
||||
options: normalizeProductOptions([variant]),
|
||||
}
|
||||
})
|
||||
|
||||
@ -74,13 +74,13 @@ export function normalizeProduct(productNode: SaleorProduct): Product {
|
||||
...rest
|
||||
} = productNode
|
||||
|
||||
const { blocks } = JSON.parse(description)
|
||||
|
||||
const product = {
|
||||
id,
|
||||
name,
|
||||
vendor: '',
|
||||
description: blocks[0]?.data.text,
|
||||
description: description
|
||||
? JSON.parse(description)?.blocks[0]?.data.text
|
||||
: '',
|
||||
path: `/${slug}`,
|
||||
slug: slug?.replace(/^\/+|\/+$/g, ''),
|
||||
price:
|
||||
|
Loading…
x
Reference in New Issue
Block a user