fix(ecommerce): total de facetas no depende de count con limit=0
Verificado en vivo contra shop.cruzcloud.net: /store/search reporta estimatedTotalHits (campo `count`) en 0 cuando limit=0, aunque facetDistribution si trae los valores correctos (limit>=1 lo reporta bien). El bucket "Todas"/"Todos" del sidebar de facetas (Fase 3b) dependia de ese campo -- ahora suma los valores de la propia facetDistribution, que da el total real sin ese problema.
This commit is contained in:
1 parent
6b5450f16f
commit
884dbd1d93
1 file changed
+14
-4
@@ -250,7 +250,17 @@ export function CatalogClient({
|
||||
const response = await fetch(`/api/search?${buildParams(omit).toString()}`, {
|
||||
signal: controller.signal,
|
||||
});
|
||||
return (await response.json()) as { facetDistribution?: FacetDistribution; count?: number };
|
||||
return (await response.json()) as { facetDistribution?: FacetDistribution };
|
||||
}
|
||||
|
||||
// El "count"/estimatedTotalHits que devuelve /api/search viene en 0 con
|
||||
// limit=0 (confirmado en vivo contra Meilisearch real -- limit>=1 lo
|
||||
// reporta bien, limit=0 no). facetDistribution si es correcto con
|
||||
// limit=0, y cada producto tiene siempre un valor para cada dimension
|
||||
// (mapProduct usa defaults como "ARI Shopping"/"Todas", nunca null), asi
|
||||
// que sumar sus valores da el total real sin depender de ese campo.
|
||||
function sumFacetValues(facet: Record<string, number> | null): number {
|
||||
return facet ? Object.values(facet).reduce((sum, value) => sum + value, 0) : 0;
|
||||
}
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
@@ -265,11 +275,11 @@ export function CatalogClient({
|
||||
const ageFacet = ageRes.facetDistribution && "ageRange" in ageRes.facetDistribution ? ageRes.facetDistribution.ageRange : null;
|
||||
setLiveFacets({
|
||||
category: categoryFacet,
|
||||
categoryTotal: categoryFacet ? (categoryRes.count ?? 0) : null,
|
||||
categoryTotal: categoryFacet ? sumFacetValues(categoryFacet) : null,
|
||||
brand: categoryIsLeafOrNone ? brandFacet : null,
|
||||
brandTotal: categoryIsLeafOrNone && brandFacet ? (brandRes.count ?? 0) : null,
|
||||
brandTotal: categoryIsLeafOrNone && brandFacet ? sumFacetValues(brandFacet) : null,
|
||||
ageRange: categoryIsLeafOrNone ? ageFacet : null,
|
||||
ageTotal: categoryIsLeafOrNone && ageFacet ? (ageRes.count ?? 0) : null,
|
||||
ageTotal: categoryIsLeafOrNone && ageFacet ? sumFacetValues(ageFacet) : null,
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
Reference in new issue
Block a user