diff --git a/workloads/ecommerce/app/catalog/page.tsx b/workloads/ecommerce/app/catalog/page.tsx index 5d5c175..deca906 100644 --- a/workloads/ecommerce/app/catalog/page.tsx +++ b/workloads/ecommerce/app/catalog/page.tsx @@ -1,6 +1,6 @@ import type { Metadata } from "next"; import { CatalogClient } from "@/components/catalog/catalog-client"; -import { getProducts } from "@/lib/headless/client"; +import { getCategories, getProducts } from "@/lib/headless/client"; export const metadata: Metadata = { title: "Catálogo", @@ -17,17 +17,31 @@ function single(value: string | string[] | undefined): string { export default async function CatalogPage({ searchParams }: CatalogPageProps) { const params = await searchParams; - const products = await getProducts(); + const [products, categories] = await Promise.all([getProducts(), getCategories()]); const category = single(params.category) || "Todos"; const collection = single(params.collection); const query = single(params.q); - const section = single(params.section); + + // Los links de navbar/tiles apuntan a categorias raiz (ej. "Mochilas y + // morrales"), pero ningun producto tiene esa categoria asignada + // directamente -- solo sus hijos ("Marvel", "Frozen", etc.). Este mapa + // expande cada raiz-con-hijos al nombre real de sus hijos para que el + // filtro siga funcionando por igualdad exacta de `product.category`. + const categoryGroups: Record = {}; + for (const node of categories) { + if (node.parentId) continue; + const children = categories.filter((child) => child.parentId === node.id); + if (children.length > 0) { + categoryGroups[node.name] = children.map((child) => child.name); + } + } return ( ) { - const products = await getProducts(); - return
{children}