mirror of
https://github.com/vercel/commerce.git
synced 2025-07-03 19:51:22 +00:00
Fix hasNonMasterVariants
This commit is contained in:
parent
cfa72b080e
commit
cc0da75a60
@ -39,12 +39,11 @@ const normalizeProduct = (
|
||||
// Currently, the Spree API doesn't return it.
|
||||
|
||||
const hasNonMasterVariants =
|
||||
(spreeProduct.relationships.variants.data as RelationType[]).length > 0
|
||||
(spreeProduct.relationships.variants.data as RelationType[]).length > 1
|
||||
|
||||
let variants: ProductVariant[]
|
||||
let options: ProductOption[] = []
|
||||
|
||||
if (hasNonMasterVariants) {
|
||||
const spreeVariantRecords = findIncludedOfType(
|
||||
spreeSuccessResponse,
|
||||
spreeProduct,
|
||||
@ -52,14 +51,15 @@ const normalizeProduct = (
|
||||
)
|
||||
|
||||
variants = spreeVariantRecords.map((spreeVariantRecord) => {
|
||||
let variantOptions: ProductOption[] = []
|
||||
|
||||
if (hasNonMasterVariants) {
|
||||
const spreeOptionValues = findIncludedOfType(
|
||||
spreeSuccessResponse,
|
||||
spreeVariantRecord,
|
||||
'option_values'
|
||||
)
|
||||
|
||||
let variantOptions: ProductOption[] = []
|
||||
|
||||
// Only include options which are used by variants.
|
||||
|
||||
spreeOptionValues.forEach((spreeOptionValue) => {
|
||||
@ -71,15 +71,13 @@ const normalizeProduct = (
|
||||
|
||||
options = expandOptions(spreeSuccessResponse, spreeOptionValue, options)
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
id: spreeVariantRecord.id,
|
||||
options: variantOptions,
|
||||
}
|
||||
})
|
||||
} else {
|
||||
variants = []
|
||||
}
|
||||
|
||||
const slug = spreeProduct.attributes.slug
|
||||
const path = `/${spreeProduct.attributes.slug}`
|
||||
|
Loading…
x
Reference in New Issue
Block a user