add fallback value for variant price

Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
Loan Laux 2021-04-26 19:12:37 +04:00
parent 652a45468b
commit 946545b091
No known key found for this signature in database
GPG Key ID: AF9E9BD6548AD52E

View File

@ -51,7 +51,11 @@ const normalizeProductVariants = (variants: [CatalogProductVariant]) => {
title, title,
pricing, pricing,
}) => { }) => {
const variantPrice = pricing[0]?.price ?? pricing[0]?.minPrice let variantPrice = pricing[0]?.price ?? pricing[0]?.minPrice
if (variantPrice === undefined) {
variantPrice = 0
}
return { return {
id: variantId, id: variantId,
@ -60,20 +64,22 @@ const normalizeProductVariants = (variants: [CatalogProductVariant]) => {
price: variantPrice, price: variantPrice,
listPrice: pricing[0]?.compareAtPrice?.amount ?? variantPrice, listPrice: pricing[0]?.compareAtPrice?.amount ?? variantPrice,
requiresShipping: true, requiresShipping: true,
// options: options?.map(({ attributeLabel, optionTitle }: CatalogProductVariant) => options:
// normalizeProductOption({ options?.map(
// id: _id, ({ _id, attributeLabel, optionTitle }: CatalogProductVariant) =>
// name: attributeLabel, normalizeProductOption({
// values: [optionTitle], id: _id,
// }) name: attributeLabel,
// ) ?? [], values: [optionTitle],
options: [ })
{ ) ?? [],
__typename: 'MultipleChoiceOption', // options: [
displayName: attributeLabel, // {
values: [{ label: optionTitle }], // __typename: 'MultipleChoiceOption',
}, // displayName: attributeLabel,
], // values: [{ label: optionTitle }],
// },
// ],
} }
} }
) )