mirror of
https://github.com/vercel/commerce.git
synced 2025-06-20 06:01:21 +00:00
saleor: adapt for displaying featured products
This commit is contained in:
parent
dfd254cbab
commit
79e916f6ee
@ -20,10 +20,25 @@ const getAllProducts = async (options: {
|
|||||||
variables?: Variables
|
variables?: Variables
|
||||||
config?: SaleorConfig
|
config?: SaleorConfig
|
||||||
preview?: boolean
|
preview?: boolean
|
||||||
|
featured?: boolean
|
||||||
}): Promise<ReturnType> => {
|
}): Promise<ReturnType> => {
|
||||||
let { config, variables = { first: 100 } } = options ?? {}
|
let { config, variables = { first: 100 }, featured } = options ?? {}
|
||||||
config = getConfig(config)
|
config = getConfig(config)
|
||||||
|
|
||||||
|
if (featured) {
|
||||||
|
const { data }: GraphQLFetcherResult = await config.fetch(query.CollectionOne, {
|
||||||
|
variables: { ...variables, categoryId: 'Q29sbGVjdGlvbjoxOQ==' },
|
||||||
|
})
|
||||||
|
|
||||||
|
debugger
|
||||||
|
|
||||||
|
const products = data.collection.products?.edges?.map(({ node: p }: ProductCountableEdge) => normalizeProduct(p)) ?? []
|
||||||
|
|
||||||
|
return {
|
||||||
|
products,
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
const { data }: GraphQLFetcherResult = await config.fetch(query.ProductMany, {
|
const { data }: GraphQLFetcherResult = await config.fetch(query.ProductMany, {
|
||||||
variables,
|
variables,
|
||||||
})
|
})
|
||||||
@ -33,6 +48,7 @@ const getAllProducts = async (options: {
|
|||||||
return {
|
return {
|
||||||
products,
|
products,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default getAllProducts
|
export default getAllProducts
|
||||||
|
@ -15,6 +15,7 @@ export async function getStaticProps({
|
|||||||
variables: { first: 12 },
|
variables: { first: 12 },
|
||||||
config,
|
config,
|
||||||
preview,
|
preview,
|
||||||
|
featured: true
|
||||||
})
|
})
|
||||||
const { categories, brands } = await commerce.getSiteInfo({ config, preview })
|
const { categories, brands } = await commerce.getSiteInfo({ config, preview })
|
||||||
const { pages } = await commerce.getAllPages({ config, preview })
|
const { pages } = await commerce.getAllPages({ config, preview })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user