Skip to content

Commit 0cf76d9

Browse files
committed
saleor: make the home page representable
1 parent 3399228 commit 0cf76d9

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

framework/saleor/api/operations/get-all-products.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { Provider, SaleorConfig } from '..'
66
import { normalizeProduct } from '../../utils'
77

88
import * as Query from '../../utils/queries'
9+
import { GraphQLFetcherResult } from '@commerce/api'
910

1011
type ReturnType = {
1112
products: Product[]
@@ -18,6 +19,7 @@ export default function getAllProductsOperation({
1819
query = Query.ProductMany,
1920
variables,
2021
config,
22+
featured,
2123
}: {
2224
query?: string
2325
variables?: any
@@ -27,7 +29,13 @@ export default function getAllProductsOperation({
2729
} = {}): Promise<ReturnType> {
2830
const { fetch, locale } = commerce.getConfig(config)
2931

30-
const { data } = await fetch(
32+
if (featured) {
33+
variables = { ...variables, categoryId: 'Q29sbGVjdGlvbjo0' };
34+
query = Query.CollectionOne
35+
}
36+
37+
38+
const { data }: GraphQLFetcherResult = await fetch(
3139
query,
3240
{ variables },
3341
{
@@ -39,11 +47,20 @@ export default function getAllProductsOperation({
3947
}
4048
)
4149

42-
const products = data.products?.edges?.map(({ node: p }: ProductCountableEdge) => normalizeProduct(p)) ?? []
50+
if (featured) {
51+
const products = data.collection.products?.edges?.map(({ node: p }: ProductCountableEdge) => normalizeProduct(p)) ?? []
52+
53+
return {
54+
products,
55+
}
56+
} else {
57+
const products = data.products?.edges?.map(({ node: p }: ProductCountableEdge) => normalizeProduct(p)) ?? []
4358

44-
return {
45-
products,
59+
return {
60+
products,
61+
}
4662
}
63+
4764
}
4865

4966
return getAllProducts

0 commit comments

Comments
 (0)