diff --git a/src/app/made-to-order/page.tsx b/src/app/made-to-order/page.tsx index c395bea..195deb3 100644 --- a/src/app/made-to-order/page.tsx +++ b/src/app/made-to-order/page.tsx @@ -20,10 +20,16 @@ function toArray(v?: string | string[]) { export default async function ProductsPage({ searchParams }: { searchParams: SearchParams }) { const categoryRows = await prisma.category.findMany({ - where: { showOnPersonalised: true }, + where: { showOnPersonalised: true, parentId: null }, orderBy: { name: 'asc' }, + include: { children: { where: { showOnPersonalised: true }, orderBy: { name: 'asc' } } }, }); - const CATEGORIES = categoryRows.map((c) => ({ value: c.slug, label: c.name })); + // Build flat list of all categories (parents and children) for filtering + const allCategories = categoryRows.flatMap((parent) => [ + { value: parent.slug, label: parent.name }, + ...parent.children.map((child) => ({ value: child.slug, label: `${parent.name} > ${child.name}` })), + ]); + const CATEGORIES = allCategories; const collectionRows = await prisma.collection.findMany({ orderBy: { name: 'asc' } }); const OCCASIONS = collectionRows.filter((c) => c.group === 'OCCASION').map((c) => ({ value: c.slug, label: c.name })); diff --git a/src/app/products/page.tsx b/src/app/products/page.tsx index 4802676..79bf433 100644 --- a/src/app/products/page.tsx +++ b/src/app/products/page.tsx @@ -20,10 +20,16 @@ function toArray(v?: string | string[]) { export default async function ReadyMadeProductsPage({ searchParams }: { searchParams: SearchParams }) { const categoryRows = await prisma.category.findMany({ - where: { showOnProducts: true }, + where: { showOnProducts: true, parentId: null }, orderBy: { name: 'asc' }, + include: { children: { where: { showOnProducts: true }, orderBy: { name: 'asc' } } }, }); - const CATEGORIES = categoryRows.map((c) => ({ value: c.slug, label: c.name })); + // Build flat list of all categories (parents and children) for filtering + const allCategories = categoryRows.flatMap((parent) => [ + { value: parent.slug, label: parent.name }, + ...parent.children.map((child) => ({ value: child.slug, label: `${parent.name} > ${child.name}` })), + ]); + const CATEGORIES = allCategories; const collectionRows = await prisma.collection.findMany({ orderBy: { name: 'asc' } }); const OCCASIONS = collectionRows.filter((c) => c.group === 'OCCASION').map((c) => ({ value: c.slug, label: c.name }));