saleor: adapt for displaying featured products

This commit is contained in:
Zaiste 2021-06-01 11:35:35 +02:00
parent dfd254cbab
commit 79e916f6ee
No known key found for this signature in database
GPG Key ID: 15DF7EBC7F2FFE35
2 changed files with 24 additions and 7 deletions

View File

@ -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,
}
}
}

View File

@ -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 })