Always dispatch actionFacetedSearchFilters hook - #1259
Open
boo-code wants to merge 1 commit into
Open
Conversation
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.
|
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! |
kpodemski
approved these changes
Jul 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
actionFacetedSearchFilters— the documented hook that lets a module add custom filters to the faceted-search adapter — was dispatched at the very end ofSearch::addControllerSpecificFilters()(src/Product/Search.php). That method contains several earlyreturnstatements (category page when a "Categories" facet is already selected,new-productswhen adate_addfilter is already set,prices-dropwhen areductionfilter is already set). Whenever one of those returns runs, theHook::exec()line is never reached, so any module listening onactionFacetedSearchFiltersis 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 theHook::exec('actionFacetedSearchFilters', ...)call out ofaddControllerSpecificFilters()and intoinitSearch(), right afteraddControllerSpecificFilters()— so it fires on every faceted query, while still running before the filters become the initial population.SearchTest::testInitSearchDispatchesFacetedSearchFiltersHookWithSelectedCategoryFacet): on a category query,initSearch(['category' => [[6]]])sets anid_categoryfilter (triggering the early return), and the test assertsactionFacetedSearchFiltersis still dispatched — red before this change, green after. Manually: register a module onactionFacetedSearchFiltersthat 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.