From 9e33bbedf002d039b04f32921118a90dc20aec32 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Fri, 28 May 2021 16:12:56 +0200 Subject: [PATCH] Fix variant selection in Vendure provider --- framework/vendure/product/get-product.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/framework/vendure/product/get-product.ts b/framework/vendure/product/get-product.ts index 735164ec1..4427707bd 100644 --- a/framework/vendure/product/get-product.ts +++ b/framework/vendure/product/get-product.ts @@ -20,6 +20,9 @@ async function getProduct({ const product = data.product if (product) { + const getOptionGroupName = (id: string): string => { + return product.optionGroups.find((og) => og.id === id)!.name + } return { product: { id: product.id, @@ -33,9 +36,13 @@ async function getProduct({ variants: product.variants.map((v) => ({ id: v.id, 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, - displayName: o.name, - values: o.group.options.map((_o) => ({ label: _o.name })), + displayName: getOptionGroupName(o.groupId), + values: [{ label: o.name }], })), })), price: {