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