Skip to content

Commit

Permalink
saleor: make the home page representable
Browse files Browse the repository at this point in the history
  • Loading branch information
zaiste committed Jun 5, 2021
1 parent 4b5bd52 commit 605448e
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions framework/saleor/api/operations/get-all-products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Provider, SaleorConfig } from '..'
import { normalizeProduct } from '../../utils'

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

type ReturnType = {
products: Product[]
Expand All @@ -18,6 +19,7 @@ export default function getAllProductsOperation({
query = Query.ProductMany,
variables,
config,
featured,
}: {
query?: string
variables?: any
Expand All @@ -27,7 +29,13 @@ export default function getAllProductsOperation({
} = {}): Promise<ReturnType> {
const { fetch, locale } = commerce.getConfig(config)

const { data } = await fetch(
if (featured) {
variables = { ...variables, categoryId: 'Q29sbGVjdGlvbjo0' };
query = Query.CollectionOne
}


const { data }: GraphQLFetcherResult = await fetch(
query,
{ variables },
{
Expand All @@ -39,11 +47,20 @@ export default function getAllProductsOperation({
}
)

const products = data.products?.edges?.map(({ node: p }: ProductCountableEdge) => normalizeProduct(p)) ?? []
if (featured) {
const products = data.collection.products?.edges?.map(({ node: p }: ProductCountableEdge) => normalizeProduct(p)) ?? []

return {
products,
}
} else {
const products = data.products?.edges?.map(({ node: p }: ProductCountableEdge) => normalizeProduct(p)) ?? []

return {
products,
return {
products,
}
}

}

return getAllProducts
Expand Down

0 comments on commit 605448e

Please sign in to comment.