feat(poc): add page parameter for collection

This commit is contained in:
Björn Meyer 2023-07-10 09:57:15 +02:00
parent ed79b5b025
commit fc39573c57
3 changed files with 5 additions and 3 deletions

View File

@ -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
});

View File

@ -1,6 +1,6 @@
export function getDefaultProductsCriteria(page: number = 1, limit: number = 15) {
return {
page: page,
p: page,
limit: limit,
associations: getDefaultProductAssociations(),
filter: [

View File

@ -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);