diff --git a/src/features/catalog/domain/offer-discovery.test.ts b/src/features/catalog/domain/offer-discovery.test.ts index 7f599c24..a5d58912 100644 --- a/src/features/catalog/domain/offer-discovery.test.ts +++ b/src/features/catalog/domain/offer-discovery.test.ts @@ -104,7 +104,7 @@ describe("offer discovery", () => { club_only_yes: 0, club_only_no: 2, have_offer_yes: 1, - have_offer_no: 3, + have_offer_no: 1, }); }); it("searches public names, classnames, offer IDs and furniture references", () => { diff --git a/src/features/catalog/domain/offer-discovery.ts b/src/features/catalog/domain/offer-discovery.ts index cf2b12ea..43efb49c 100644 --- a/src/features/catalog/domain/offer-discovery.ts +++ b/src/features/catalog/domain/offer-discovery.ts @@ -79,28 +79,6 @@ export function discoverOffers( ); } - // Apply multiple filters - for (const filterKey in filters) { - const filterValue = filters[filterKey]; - if (filterValue && filterValue !== "all") { - matches = matches.filter((item) => - matchesFilter(item, filterValue as OfferFilter), - ); - } - } - - const counts = { - all: matches.length, - free: 0, - paid: 0, - bundles: 0, - limited: 0, - club_only_yes: 0, - club_only_no: 0, - have_offer_yes: 0, - have_offer_no: 0, - }; - // Calculate facet counts based on *all* items matching the text query, before specific filters are applied const initialMatchesForFacets = items.filter((item) => { if (exactId !== null) return String(item.id) === exactId; @@ -115,6 +93,30 @@ export function discoverOffers( return true; // If no text query, all items are initial matches }); + const allCount = initialMatchesForFacets.length; + + // Apply multiple filters + for (const filterKey in filters) { + const filterValue = filters[filterKey]; + if (filterValue && filterValue !== "all") { + matches = matches.filter((item) => + matchesFilter(item, filterValue as OfferFilter), + ); + } + } + + const counts = { + all: allCount, + free: 0, + paid: 0, + bundles: 0, + limited: 0, + club_only_yes: 0, + club_only_no: 0, + have_offer_yes: 0, + have_offer_no: 0, + }; + for (const item of initialMatchesForFacets) { for (const facet of OFFER_FILTERS) { if (facet !== "all" && matchesFilter(item, facet)) counts[facet] += 1;