diff --git a/lib/bigcommerce/products/use-search.tsx b/lib/bigcommerce/products/use-search.tsx index 34cc0ed8b..fd3a8ece3 100644 --- a/lib/bigcommerce/products/use-search.tsx +++ b/lib/bigcommerce/products/use-search.tsx @@ -12,11 +12,12 @@ export type SearchProductsInput = { search?: string categoryId?: number brandId?: number + sort?: string } export const fetcher: HookFetcher = ( options, - { search, categoryId, brandId }, + { search, categoryId, brandId, sort }, fetch ) => { // Use a dummy base as we only care about the relative path @@ -27,6 +28,7 @@ export const fetcher: HookFetcher = ( url.searchParams.set('category', String(categoryId)) if (Number.isInteger(categoryId)) url.searchParams.set('brand', String(brandId)) + if (sort) url.searchParams.set('sort', sort) return fetch({ url: url.pathname + url.search, @@ -45,6 +47,7 @@ export function extendHook( ['search', input.search], ['categoryId', input.categoryId], ['brandId', input.brandId], + ['sort', input.sort], ], customFetcher, { revalidateOnFocus: false, ...swrOptions } diff --git a/pages/search.tsx b/pages/search.tsx index e1fa17cfa..f2303417c 100644 --- a/pages/search.tsx +++ b/pages/search.tsx @@ -17,7 +17,7 @@ export async function getStaticProps({ preview }: GetStaticPropsContext) { } } -export default function Home({ +export default function Search({ categories, brands, }: InferGetStaticPropsType) { @@ -39,6 +39,7 @@ export default function Home({ search: typeof q === 'string' ? q : '', categoryId: activeCategory?.entityId, brandId: activeBrand?.entityId, + sort: typeof sort === 'string' ? sort : '', }) return ( @@ -178,7 +179,7 @@ export default function Home({ ) } -Home.Layout = Layout +Search.Layout = Layout function useSearchMeta(asPath: string) { const [category, setCategory] = useState()