mirror of
https://github.com/vercel/commerce.git
synced 2025-06-18 13:11:23 +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) {
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user