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