From 79e916f6ee514a08e2423f216990d4ee44d704d5 Mon Sep 17 00:00:00 2001 From: Zaiste Date: Tue, 1 Jun 2021 11:35:35 +0200 Subject: [PATCH] saleor: adapt for displaying featured products --- framework/saleor/product/get-all-products.ts | 30 +++++++++++++++----- pages/index.tsx | 1 + 2 files changed, 24 insertions(+), 7 deletions(-) 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 })