Skip to content

Always dispatch actionFacetedSearchFilters hook - #1259

Open
boo-code wants to merge 1 commit into
PrestaShop:devfrom
boo-code:fix/faceted-filters-hook-early-return-1239
Open

Always dispatch actionFacetedSearchFilters hook#1259
boo-code wants to merge 1 commit into
PrestaShop:devfrom
boo-code:fix/faceted-filters-hook-early-return-1239

Conversation

@boo-code

Copy link
Copy Markdown
Contributor
Questions Answers
Description? actionFacetedSearchFilters — the documented hook that lets a module add custom filters to the faceted-search adapter — was dispatched at the very end of Search::addControllerSpecificFilters() (src/Product/Search.php). That method contains several early return statements (category page when a "Categories" facet is already selected, new-products when a date_add filter is already set, prices-drop when a reduction filter is already set). Whenever one of those returns runs, the Hook::exec() line is never reached, so any module listening on actionFacetedSearchFilters is silently bypassed and its filters are dropped from the final product query. This is easy to miss because the hook works fine on plain category/manufacturer/supplier/search pages and on feature/attribute facets. Fix: move the Hook::exec('actionFacetedSearchFilters', ...) call out of addControllerSpecificFilters() and into initSearch(), right after addControllerSpecificFilters() — so it fires on every faceted query, while still running before the filters become the initial population.
Type? bug fix
BC breaks? no
Deprecations? no
Fixed ticket? Fixes #1239.
How to test? A unit test is included (SearchTest::testInitSearchDispatchesFacetedSearchFiltersHookWithSelectedCategoryFacet): on a category query, initSearch(['category' => [[6]]]) sets an id_category filter (triggering the early return), and the test asserts actionFacetedSearchFilters is still dispatched — red before this change, green after. Manually: register a module on actionFacetedSearchFilters that calls $params['search']->getSearchAdapter()->addFilter('id_product', [1, 2, 3]);, open a category page, then select a "Categories" facet — before, the custom filter disappears from the results; after, it is applied in both cases.
Sponsor company

addControllerSpecificFilters() dispatched the actionFacetedSearchFilters hook at
its very end, but the method has early return statements (category page with an
already selected "Categories" facet, new-products with a date_add filter,
prices-drop with a reduction filter). Whenever one of those returns ran, the
hook was silently skipped and any module adding filters through it had its
filters dropped from the final query.

Move the Hook::exec() call to initSearch(), right after
addControllerSpecificFilters(), so the documented extension point fires on every
faceted query regardless of the controller specific early returns. The hook
still runs before the filters are turned into the initial population, so module
filters keep being part of the query.
@ps-jarvis

Copy link
Copy Markdown

Hello @boo-code!

This is your first pull request on ps_facetedsearch repository of the PrestaShop project.

Thank you, and welcome to this Open Source community!

@github-project-automation github-project-automation Bot moved this to Ready for review in PR Dashboard Jun 27, 2026
@ps-jarvis ps-jarvis added the Waiting for QA Status: Action required, Waiting for test feedback label Jul 6, 2026
@ps-jarvis ps-jarvis moved this from Ready for review to To be tested in PR Dashboard Jul 6, 2026
@kpodemski kpodemski added the Waiting for QA by Community Status: Action required, Waiting for test feedback by Community label Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Waiting for QA by Community Status: Action required, Waiting for test feedback by Community Waiting for QA Status: Action required, Waiting for test feedback

Projects

Status: To be tested

Development

Successfully merging this pull request may close these issues.

actionFacetedSearchFilters hook is skipped when a "Categories" facet is active (early return in Search::addControllerSpecificFilters)

3 participants