mirror of
https://github.com/vercel/commerce.git
synced 2025-06-18 21:21:21 +00:00
Update helpers.ts
This commit is contained in:
parent
59dedf58cc
commit
639863bb35
@ -8,18 +8,18 @@ export type SelectedOptions = {
|
|||||||
export function getVariant(product: Product, opts: SelectedOptions) {
|
export function getVariant(product: Product, opts: SelectedOptions) {
|
||||||
const variant = product.variants.find((variant) => {
|
const variant = product.variants.find((variant) => {
|
||||||
return Object.entries(opts).every(([key, value]) =>
|
return Object.entries(opts).every(([key, value]) =>
|
||||||
variant.options.find((option) => {
|
value
|
||||||
|
? variant.options.find((option) => {
|
||||||
if (
|
if (
|
||||||
option.__typename === 'MultipleChoiceOption' &&
|
option.__typename === 'MultipleChoiceOption' &&
|
||||||
option.displayName.toLowerCase() === key.toLowerCase()
|
option.displayName.toLowerCase() === key.toLowerCase()
|
||||||
) {
|
) {
|
||||||
return option.values.find((v) => v.label.toLowerCase() === value)
|
return option.values.find((v) => v.label.toLowerCase() === value)
|
||||||
} else if (!value) {
|
|
||||||
return !variant.options.find(
|
|
||||||
(v) => v.displayName.toLowerCase() === key
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
: !variant.options.find(
|
||||||
|
(v) => v.displayName.toLowerCase() === key.toLowerCase()
|
||||||
|
)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
return variant
|
return variant
|
||||||
|
Loading…
x
Reference in New Issue
Block a user