diff --git a/framework/bigcommerce/api/endpoints/catalog/products/get-products.ts b/framework/bigcommerce/api/endpoints/catalog/products/get-products.ts index 8471767aa..707f43811 100644 --- a/framework/bigcommerce/api/endpoints/catalog/products/get-products.ts +++ b/framework/bigcommerce/api/endpoints/catalog/products/get-products.ts @@ -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('-') diff --git a/framework/bigcommerce/product/use-search.tsx b/framework/bigcommerce/product/use-search.tsx index 0ee135032..c9ac8f9a0 100644 --- a/framework/bigcommerce/product/use-search.tsx +++ b/framework/bigcommerce/product/use-search.tsx @@ -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 @@ -11,13 +11,9 @@ export type SearchProductsInput = { sort?: string } -export const handler: SWRHook< - SearchProductsData, - SearchProductsInput, - SearchProductsInput -> = { +export const handler: SWRHook = { fetchOptions: { - url: '/api/bigcommerce/catalog/products', + url: '/api/catalog/products', method: 'GET', }, fetcher({ input: { search, categoryId, brandId, sort }, options, fetch }) { diff --git a/framework/commerce/product/use-search.tsx b/framework/commerce/product/use-search.tsx index d2b782045..a80d598ce 100644 --- a/framework/commerce/product/use-search.tsx +++ b/framework/commerce/product/use-search.tsx @@ -1,14 +1,14 @@ import { useHook, useSWRHook } from '../utils/use-hook' import { SWRFetcher } from '../utils/default-fetcher' import type { HookFetcherFn, SWRHook } from '../utils/types' -import type { SearchProductsData } from '../types' -import { Provider } from '..' +import type { SearchProductsHook } from '../types/product' +import type { Provider } from '..' export type UseSearch< - H extends SWRHook = SWRHook + H extends SWRHook = SWRHook > = ReturnType -export const fetcher: HookFetcherFn = SWRFetcher +export const fetcher: HookFetcherFn = SWRFetcher const fn = (provider: Provider) => provider.products?.useSearch! diff --git a/framework/commerce/types/product.ts b/framework/commerce/types/product.ts index f69827f89..2ac45389e 100644 --- a/framework/commerce/types/product.ts +++ b/framework/commerce/types/product.ts @@ -42,8 +42,23 @@ export type Product = { options: ProductOption[] } +export type SearchProductsBody = { + search?: string + categoryId?: string + brandId?: string + sort?: string +} + export type ProductTypes = { product: Product + searchBody: SearchProductsBody +} + +export type SearchProductsHook = { + data: T['product'][] + body: T['searchBody'] + input: T['searchBody'] + fetchInput: T['searchBody'] } export type ProductsSchema = { @@ -55,12 +70,7 @@ export type ProductsSchema = { products: T['product'][] found: boolean } - body: { - search?: string - category?: string - brand?: string - sort?: string - } + body: SearchProductsHook['body'] } } }