mirror of
https://github.com/vercel/commerce.git
synced 2025-07-25 11:11:24 +00:00
Updated useSearch hook
This commit is contained in:
@@ -12,7 +12,7 @@ const LIMIT = 12
|
||||
// Return current cart info
|
||||
const getProducts: ProductsEndpoint['handlers']['getProducts'] = async ({
|
||||
res,
|
||||
body: { search, category, brand, sort },
|
||||
body: { search, categoryId, brandId, sort },
|
||||
config,
|
||||
commerce,
|
||||
}) => {
|
||||
@@ -24,11 +24,11 @@ const getProducts: ProductsEndpoint['handlers']['getProducts'] = async ({
|
||||
|
||||
if (search) url.searchParams.set('keyword', search)
|
||||
|
||||
if (category && Number.isInteger(Number(category)))
|
||||
url.searchParams.set('categories:in', category)
|
||||
if (categoryId && Number.isInteger(Number(categoryId)))
|
||||
url.searchParams.set('categories:in', categoryId)
|
||||
|
||||
if (brand && Number.isInteger(Number(brand)))
|
||||
url.searchParams.set('brand_id', brand)
|
||||
if (brandId && Number.isInteger(Number(brandId)))
|
||||
url.searchParams.set('brand_id', brandId)
|
||||
|
||||
if (sort) {
|
||||
const [_sort, direction] = sort.split('-')
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import useSearch, { UseSearch } from '@commerce/product/use-search'
|
||||
import type { SearchProductsData } from '../api/catalog/products'
|
||||
import type { SearchProductsHook } from '../types/product'
|
||||
|
||||
export default useSearch as UseSearch<typeof handler>
|
||||
|
||||
@@ -11,13 +11,9 @@ export type SearchProductsInput = {
|
||||
sort?: string
|
||||
}
|
||||
|
||||
export const handler: SWRHook<
|
||||
SearchProductsData,
|
||||
SearchProductsInput,
|
||||
SearchProductsInput
|
||||
> = {
|
||||
export const handler: SWRHook<SearchProductsHook> = {
|
||||
fetchOptions: {
|
||||
url: '/api/bigcommerce/catalog/products',
|
||||
url: '/api/catalog/products',
|
||||
method: 'GET',
|
||||
},
|
||||
fetcher({ input: { search, categoryId, brandId, sort }, options, fetch }) {
|
||||
|
Reference in New Issue
Block a user