ensure products have at least one variant
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { getConfig, SwellConfig } from '../api'
|
||||
import { normalizeProduct } from '../utils/normalize'
|
||||
import { Product } from '@commerce/types'
|
||||
import { SwellProduct } from '../types'
|
||||
|
||||
type Variables = {
|
||||
first?: number
|
||||
@@ -23,12 +24,10 @@ const getAllProducts = async (options: {
|
||||
limit: variables.first,
|
||||
},
|
||||
])
|
||||
const products = results.map((product) => {
|
||||
if (product.variants) {
|
||||
product.variants = product.variants.results
|
||||
}
|
||||
return normalizeProduct(product) ?? []
|
||||
})
|
||||
const products = results.map((product: SwellProduct) =>
|
||||
normalizeProduct(product)
|
||||
)
|
||||
|
||||
return {
|
||||
products,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { GraphQLFetcherResult } from '@commerce/api'
|
||||
import { getConfig, SwellConfig } from '../api'
|
||||
import { normalizeProduct, getProductQuery } from '../utils'
|
||||
import { normalizeProduct } from '../utils'
|
||||
|
||||
type Variables = {
|
||||
slug: string
|
||||
|
||||
@@ -5,6 +5,8 @@ import { normalizeProduct } from '../utils'
|
||||
|
||||
import { Product } from '@commerce/types'
|
||||
|
||||
import { SwellProduct } from '../types'
|
||||
|
||||
export default useSearch as UseSearch<typeof handler>
|
||||
|
||||
export type SearchProductsInput = {
|
||||
@@ -43,12 +45,9 @@ export const handler: SWRHook<
|
||||
variables: { category: categoryId, search, sort: mappedSort },
|
||||
})
|
||||
|
||||
const products = results.map((product) => {
|
||||
if (product.variants) {
|
||||
product.variants = product.variants?.results
|
||||
}
|
||||
return normalizeProduct(product)
|
||||
})
|
||||
const products = results.map((product: SwellProduct) =>
|
||||
normalizeProduct(product)
|
||||
)
|
||||
|
||||
return {
|
||||
products,
|
||||
|
||||
Reference in New Issue
Block a user