Skip to content

Commit

Permalink
fix: Fix filtering by categories and collections (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
soniaklimas authored Dec 30, 2024
1 parent c2469e8 commit 152c8fa
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 42 deletions.
4 changes: 4 additions & 0 deletions apps/storefront/src/app/[locale]/(main)/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export default async function Page(props: { searchParams: SearchParams }) {
sortBy = DEFAULT_SORT_BY,
q: query = "",
limit,
category,
collection,
...rest
} = searchParams;
const { results, pageInfo } = await searchService.search(
Expand All @@ -77,6 +79,8 @@ export default async function Page(props: { searchParams: SearchParams }) {
before,
sortBy,
filters: rest,
category,
collection,
},
searchContext,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,70 @@
query SearchProductQuery(
$after: String
$before: String
$categorySlug: String
$channel: String!
$collectionSlug: String
$filter: ProductFilterInput
$first: Int
$languageCode: LanguageCodeEnum!
$last: Int
$search: String
$searchByCategory: Boolean!
$searchByCollection: Boolean!
$searchByProducts: Boolean!
$sortBy: ProductOrder
$languageCode: LanguageCodeEnum!
$where: ProductWhereInput
) {
category(slug: $categorySlug) @include(if: $searchByCategory) {
products(
after: $after
before: $before
channel: $channel
filter: $filter
first: $first
last: $last
sortBy: $sortBy
where: $where
) {
edges {
node {
...SearchProductFragment
}
}
pageInfo {
startCursor
endCursor
hasNextPage
hasPreviousPage
}
totalCount
}
}
collection(slug: $collectionSlug, channel: $channel)
@include(if: $searchByCollection) {
products(
after: $after
before: $before
filter: $filter
first: $first
last: $last
sortBy: $sortBy
where: $where
) {
edges {
node {
...SearchProductFragment
}
}
pageInfo {
startCursor
endCursor
hasNextPage
hasPreviousPage
}
totalCount
}
}
products(
after: $after
before: $before
Expand All @@ -20,7 +75,7 @@ query SearchProductQuery(
search: $search
sortBy: $sortBy
where: $where
) {
) @include(if: $searchByProducts) {
edges {
node {
...SearchProductFragment
Expand Down
Loading

0 comments on commit 152c8fa

Please sign in to comment.