From f5ec8e17a4740cb9ac554f89a4bbc3e2c5701a6e Mon Sep 17 00:00:00 2001 From: Zaiste Date: Thu, 13 May 2021 13:22:57 +0200 Subject: [PATCH] saleor: integrate collections --- framework/saleor/product/use-search.tsx | 2 +- framework/saleor/utils/get-categories.ts | 2 +- .../queries/get-collection-products-query.ts | 18 ++++++------------ 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/framework/saleor/product/use-search.tsx b/framework/saleor/product/use-search.tsx index fc27877d2..5a9431384 100644 --- a/framework/saleor/product/use-search.tsx +++ b/framework/saleor/product/use-search.tsx @@ -45,7 +45,7 @@ export const handler: SWRHook< let edges if (categoryId) { - edges = data.node?.products?.edges ?? [] + edges = data.collection?.products?.edges ?? [] // FIXME @zaiste, no `vendor` in Saleor // if (brandId) { // edges = edges.filter( diff --git a/framework/saleor/utils/get-categories.ts b/framework/saleor/utils/get-categories.ts index 4c976c0ee..9dd6b84a8 100644 --- a/framework/saleor/utils/get-categories.ts +++ b/framework/saleor/utils/get-categories.ts @@ -1,5 +1,5 @@ import { SaleorConfig } from '../api' -import { Collection, CollectionCountableEdge } from '../schema' +import { CollectionCountableEdge } from '../schema' import { getSiteCollectionsQuery } from './queries/' export type Category = { diff --git a/framework/saleor/utils/queries/get-collection-products-query.ts b/framework/saleor/utils/queries/get-collection-products-query.ts index 7631a81ab..09625d290 100644 --- a/framework/saleor/utils/queries/get-collection-products-query.ts +++ b/framework/saleor/utils/queries/get-collection-products-query.ts @@ -3,21 +3,15 @@ import { productConnection } from './get-all-products-query' export const getCollectionProductsQuery = /* GraphQL */ ` query getProductsFromCollection( $categoryId: ID! - $first: Int = 250 - $sortKey: ProductCollectionSortKeys = RELEVANCE - $reverse: Boolean = false + $first: Int = 100 + $channel: String = "default-channel" ) { - node(id: $categoryId) { + collection(id: $categoryId, channel: $channel) { id - ... on Collection { - products( - first: $first - sortKey: $sortKey - reverse: $reverse - ) { - ${productConnection} - } + products(first: $first) { + ...productConnection } } } + ${productConnection} `