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