diff --git a/framework/saleor/product/get-all-products.ts b/framework/saleor/product/get-all-products.ts index 2d37f283f..c2c5fe811 100644 --- a/framework/saleor/product/get-all-products.ts +++ b/framework/saleor/product/get-all-products.ts @@ -20,18 +20,34 @@ const getAllProducts = async (options: { variables?: Variables config?: SaleorConfig preview?: boolean + featured?: boolean }): Promise => { - 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, + } } } diff --git a/pages/index.tsx b/pages/index.tsx index 02142f3b0..3f1b6502a 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -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 })