From 639863bb354fc6a90fae5b52ab0facecede974b7 Mon Sep 17 00:00:00 2001 From: cond0r Date: Wed, 3 Mar 2021 20:36:36 +0200 Subject: [PATCH] Update helpers.ts --- components/product/helpers.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/components/product/helpers.ts b/components/product/helpers.ts index 5dd1e2d04..44bdeca97 100644 --- a/components/product/helpers.ts +++ b/components/product/helpers.ts @@ -8,18 +8,18 @@ export type SelectedOptions = { export function getVariant(product: Product, opts: SelectedOptions) { const variant = product.variants.find((variant) => { return Object.entries(opts).every(([key, value]) => - variant.options.find((option) => { - if ( - option.__typename === 'MultipleChoiceOption' && - option.displayName.toLowerCase() === key.toLowerCase() - ) { - return option.values.find((v) => v.label.toLowerCase() === value) - } else if (!value) { - return !variant.options.find( - (v) => v.displayName.toLowerCase() === key + value + ? variant.options.find((option) => { + if ( + option.__typename === 'MultipleChoiceOption' && + option.displayName.toLowerCase() === key.toLowerCase() + ) { + return option.values.find((v) => v.label.toLowerCase() === value) + } + }) + : !variant.options.find( + (v) => v.displayName.toLowerCase() === key.toLowerCase() ) - } - }) ) }) return variant