mirror of
https://github.com/vercel/commerce.git
synced 2025-05-15 05:56:59 +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 };
|
params: { collection: string };
|
||||||
searchParams?: { [key: string]: string | string[] | undefined };
|
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 { sortKey, reverse } = sorting.find((item) => item.slug === sort) || defaultSort;
|
||||||
|
|
||||||
const products = await getCollectionProducts({
|
const products = await getCollectionProducts({
|
||||||
collection: params.collection,
|
collection: params.collection,
|
||||||
|
page: page ? parseInt(page) : 1,
|
||||||
sortKey,
|
sortKey,
|
||||||
reverse
|
reverse
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
export function getDefaultProductsCriteria(page: number = 1, limit: number = 15) {
|
export function getDefaultProductsCriteria(page: number = 1, limit: number = 15) {
|
||||||
return {
|
return {
|
||||||
page: page,
|
p: page,
|
||||||
limit: limit,
|
limit: limit,
|
||||||
associations: getDefaultProductAssociations(),
|
associations: getDefaultProductAssociations(),
|
||||||
filter: [
|
filter: [
|
||||||
|
@ -104,6 +104,7 @@ export async function getSearchCollectionProducts(params?: {
|
|||||||
|
|
||||||
export async function getCollectionProducts(params?: {
|
export async function getCollectionProducts(params?: {
|
||||||
collection: string;
|
collection: string;
|
||||||
|
page?: number;
|
||||||
reverse?: boolean;
|
reverse?: boolean;
|
||||||
sortKey?: string;
|
sortKey?: string;
|
||||||
categoryId?: string;
|
categoryId?: string;
|
||||||
@ -129,7 +130,7 @@ export async function getCollectionProducts(params?: {
|
|||||||
|
|
||||||
if (category) {
|
if (category) {
|
||||||
const criteria = !params?.defaultSearchCriteria
|
const criteria = !params?.defaultSearchCriteria
|
||||||
? getDefaultProductsCriteria()
|
? getDefaultProductsCriteria(params?.page)
|
||||||
: params?.defaultSearchCriteria;
|
: params?.defaultSearchCriteria;
|
||||||
const productsCriteria = { ...criteria, ...sorting };
|
const productsCriteria = { ...criteria, ...sorting };
|
||||||
res = await requestCategoryProductsCollection(category, productsCriteria);
|
res = await requestCategoryProductsCollection(category, productsCriteria);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user