mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 15:36:58 +00:00
CKAD-75-store-categories-categoryPages
This commit is contained in:
parent
737612656f
commit
a85584d999
@ -1,17 +1,53 @@
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import useSearch, { UseSearch } from '@commerce/product/use-search'
|
||||
import type { SearchProductsHook } from '../types/product'
|
||||
import epClient from '../utils/ep-client'
|
||||
import normalizeProducts from '../utils/normalize'
|
||||
|
||||
export default useSearch as UseSearch<typeof handler>
|
||||
|
||||
export const handler: SWRHook<any> = {
|
||||
export type SearchProductsInput = {
|
||||
search?: string
|
||||
sort?: string
|
||||
}
|
||||
|
||||
export const handler: SWRHook<SearchProductsHook> = {
|
||||
fetchOptions: {
|
||||
query: '',
|
||||
url: 'Products',
|
||||
method: 'All',
|
||||
},
|
||||
async fetcher({ input, options, fetch }) {},
|
||||
useHook: () => () => {
|
||||
return {
|
||||
data: {
|
||||
products: [],
|
||||
},
|
||||
async fetcher({ input: { search, sort }, options, fetch }) {
|
||||
// Use a dummy base as we only care about the relative path
|
||||
let url = new URL(options.url!, 'http://api.moltin.com')
|
||||
|
||||
if (search) url.searchParams.set('search', search)
|
||||
if (sort) url.searchParams.set('sort', sort)
|
||||
|
||||
if(sort){
|
||||
let productsRes = await epClient.PCM.Sort(sort).All();
|
||||
let products = await normalizeProducts(productsRes.data);
|
||||
return {
|
||||
products: products,
|
||||
}
|
||||
}
|
||||
else{
|
||||
let productsRes = await epClient.PCM.All()
|
||||
let products = await normalizeProducts(productsRes.data);
|
||||
return {
|
||||
products: products
|
||||
}
|
||||
}
|
||||
},
|
||||
useHook: ({ useData }) => (input = {}) => {
|
||||
return useData({
|
||||
input: [
|
||||
['search', input.search],
|
||||
['sort', input.sort],
|
||||
],
|
||||
swrOptions: {
|
||||
revalidateOnFocus: false,
|
||||
...input.swrOptions,
|
||||
},
|
||||
})
|
||||
},
|
||||
}
|
1
framework/elasticpath/types/product.tsx
Normal file
1
framework/elasticpath/types/product.tsx
Normal file
@ -0,0 +1 @@
|
||||
export * from '@commerce/types/product'
|
28456
package-lock.json
generated
Normal file
28456
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user