diff --git a/components/product/helpers.ts b/components/product/helpers.ts index 9195727c3..19ec2a171 100644 --- a/components/product/helpers.ts +++ b/components/product/helpers.ts @@ -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) } }) ) diff --git a/framework/saleor/utils/normalize.ts b/framework/saleor/utils/normalize.ts index 329914a47..4c1894647 100644 --- a/framework/saleor/utils/normalize.ts +++ b/framework/saleor/utils/normalize.ts @@ -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: