mirror of
https://github.com/vercel/commerce.git
synced 2025-05-14 21:47:51 +00:00
feat(poc): add page parameter for collection
This commit is contained in:
parent
ed79b5b025
commit
fc39573c57
@ -31,11 +31,12 @@ export default async function CategoryPage({
|
||||
params: { collection: string };
|
||||
searchParams?: { [key: string]: string | string[] | undefined };
|
||||
}) {
|
||||
const { sort } = searchParams as { [key: string]: string };
|
||||
const { sort, page } = searchParams as { [key: string]: string };
|
||||
const { sortKey, reverse } = sorting.find((item) => item.slug === sort) || defaultSort;
|
||||
|
||||
const products = await getCollectionProducts({
|
||||
collection: params.collection,
|
||||
page: page ? parseInt(page) : 1,
|
||||
sortKey,
|
||||
reverse
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
export function getDefaultProductsCriteria(page: number = 1, limit: number = 15) {
|
||||
return {
|
||||
page: page,
|
||||
p: page,
|
||||
limit: limit,
|
||||
associations: getDefaultProductAssociations(),
|
||||
filter: [
|
||||
|
@ -104,6 +104,7 @@ export async function getSearchCollectionProducts(params?: {
|
||||
|
||||
export async function getCollectionProducts(params?: {
|
||||
collection: string;
|
||||
page?: number;
|
||||
reverse?: boolean;
|
||||
sortKey?: string;
|
||||
categoryId?: string;
|
||||
@ -129,7 +130,7 @@ export async function getCollectionProducts(params?: {
|
||||
|
||||
if (category) {
|
||||
const criteria = !params?.defaultSearchCriteria
|
||||
? getDefaultProductsCriteria()
|
||||
? getDefaultProductsCriteria(params?.page)
|
||||
: params?.defaultSearchCriteria;
|
||||
const productsCriteria = { ...criteria, ...sorting };
|
||||
res = await requestCategoryProductsCollection(category, productsCriteria);
|
||||
|
Loading…
x
Reference in New Issue
Block a user