mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 13:41:22 +00:00
Fix variant selection in Vendure provider
This commit is contained in:
parent
60dac1654b
commit
9e33bbedf0
@ -20,6 +20,9 @@ async function getProduct({
|
|||||||
const product = data.product
|
const product = data.product
|
||||||
|
|
||||||
if (product) {
|
if (product) {
|
||||||
|
const getOptionGroupName = (id: string): string => {
|
||||||
|
return product.optionGroups.find((og) => og.id === id)!.name
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
product: {
|
product: {
|
||||||
id: product.id,
|
id: product.id,
|
||||||
@ -33,9 +36,13 @@ async function getProduct({
|
|||||||
variants: product.variants.map((v) => ({
|
variants: product.variants.map((v) => ({
|
||||||
id: v.id,
|
id: v.id,
|
||||||
options: v.options.map((o) => ({
|
options: v.options.map((o) => ({
|
||||||
|
// This __typename property is required in order for the correct
|
||||||
|
// variant selection to work, see `components/product/helpers.ts`
|
||||||
|
// `getVariant()` function.
|
||||||
|
__typename: 'MultipleChoiceOption',
|
||||||
id: o.id,
|
id: o.id,
|
||||||
displayName: o.name,
|
displayName: getOptionGroupName(o.groupId),
|
||||||
values: o.group.options.map((_o) => ({ label: _o.name })),
|
values: [{ label: o.name }],
|
||||||
})),
|
})),
|
||||||
})),
|
})),
|
||||||
price: {
|
price: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user