import { Metadata } from 'next'; import { notFound } from 'next/navigation'; import Grid from 'components/grid'; import Collections from 'components/layout/search/collections'; import FilterList from 'components/layout/search/filter'; import ProductGridItems from 'components/layout/product-grid-items'; import Pagination from 'components/collection/pagination'; import { getCollection, getCollectionProducts } from 'lib/shopware'; import { transformHandle } from 'lib/shopware/transform'; import { defaultSort, sorting } from 'lib/constants'; export const runtime = 'edge'; export async function generateMetadata({ params }: { params: { collection: string }; }): Promise { // see https://github.com/facebook/react/issues/25994 const collectionName = decodeURIComponent(transformHandle(params?.collection ?? '')); if (collectionName === 'react_devtools_backend_compact.js.map') { return {}; } const collection = await getCollection(collectionName); if (!collection) return notFound(); return { title: collection.seo?.title || collection.title, description: collection.seo?.description || collection.description || `${collection.title} products` }; } export default async function CategoryPage({ params, searchParams }: { params: { collection: string }; searchParams?: { [key: string]: string | string[] | undefined }; }) { const { sort, page } = searchParams as { [key: string]: string }; const { sortKey, reverse } = sorting.find((item) => item.slug === sort) || defaultSort; // see https://github.com/facebook/react/issues/25994 const collectionName = decodeURIComponent(transformHandle(params?.collection ?? '')); if (collectionName === 'react_devtools_backend_compact.js.map') { return null; } const { products, total, limit } = await getCollectionProducts({ collection: collectionName, page: page ? parseInt(page) : 1, sortKey, reverse }); return (
{products.length === 0 ? (

{`No products found in this collection`}

) : (
{total > limit ? ( ) : null}
)}
); }