mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 15:36:58 +00:00
Merge pull request #8 from trikatechnologies/CKAD-75-store-categories-categoryPages
Ckad 75 store categories category pages
This commit is contained in:
commit
627289b1c2
@ -1,17 +1,53 @@
|
|||||||
import { SWRHook } from '@commerce/utils/types'
|
import { SWRHook } from '@commerce/utils/types'
|
||||||
import useSearch, { UseSearch } from '@commerce/product/use-search'
|
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 default useSearch as UseSearch<typeof handler>
|
||||||
|
|
||||||
export const handler: SWRHook<any> = {
|
export type SearchProductsInput = {
|
||||||
|
search?: string
|
||||||
|
sort?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const handler: SWRHook<SearchProductsHook> = {
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
query: '',
|
url: 'Products',
|
||||||
|
method: 'All',
|
||||||
},
|
},
|
||||||
async fetcher({ input, options, fetch }) {},
|
async fetcher({ input: { search, sort }, options, fetch }) {
|
||||||
useHook: () => () => {
|
// 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 {
|
return {
|
||||||
data: {
|
products: 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,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
}
|
}
|
@ -16,7 +16,9 @@ import { handler as useSignup } from './auth/use-signup'
|
|||||||
|
|
||||||
import { handler as useCheckout } from './checkout/use-checkout'
|
import { handler as useCheckout } from './checkout/use-checkout'
|
||||||
import { handler as useCards } from './customer/card/use-cards'
|
import { handler as useCards } from './customer/card/use-cards'
|
||||||
|
import { handler as useAddCardItem } from './customer/card/use-add-item'
|
||||||
import { handler as useAddresses } from './customer/address/use-addresses'
|
import { handler as useAddresses } from './customer/address/use-addresses'
|
||||||
|
import { handler as useAddAddressItem } from './customer/address/use-add-item'
|
||||||
|
|
||||||
import {fetcher} from './fetcher'
|
import {fetcher} from './fetcher'
|
||||||
|
|
||||||
@ -36,10 +38,12 @@ export const elasticpathProvider = {
|
|||||||
customer: {
|
customer: {
|
||||||
useCustomer,
|
useCustomer,
|
||||||
card: {
|
card: {
|
||||||
useCards
|
useCards,
|
||||||
|
useAddItem: useAddCardItem,
|
||||||
},
|
},
|
||||||
address: {
|
address: {
|
||||||
useAddresses
|
useAddresses,
|
||||||
|
useAddItem: useAddAddressItem,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
products: { useSearch },
|
products: { useSearch },
|
||||||
|
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