Assign language to the facets template so theme overrides can read it#1257
Conversation
|
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! |
SiraDIOP
left a comment
There was a problem hiding this comment.
Hello @boo-code,
Thanks for your PR , i tested it :
Environment: dev branch, Docker (prestashop-develop-prestashop-git-1), Hummingbird theme, ps_facetedsearch module updated to this PR's branch, cache cleared.
Steps:
Checked out PR #1257 branch, ran composer install --no-dev -o.
Deployed the module into the container, cleared Smarty/var cache, ran module upgrade ps_facetedsearch.
Switched front office theme to Hummingbird.
Opened a category page with faceted search active.
Result: Fatal error, category page does not render:
Fatal error: Uncaught Error: Cannot use object of type Language as array in .../facets.tpl.php:491
Root cause: SearchProvider::renderFacets() now assigns 'language' => $this->module->getContext()->language (the raw Language object). facets.tpl reads it via {$language.is_rtl}, which Smarty compiles to array access. Language does not implement ArrayAccess, so this throws a fatal error.
Impact: This does not fix #41846, it makes it worse. Before this PR, the page rendered with a warning and degraded slider markup. After this PR, the category page is fully broken (fatal error) on Hummingbird.
Marking as blocking.
Did i miss something?
Thanks
renderFacets() never assigned `language` to Smarty when rendering the faceted-search block, so themes that override facets.tpl and reference it - the Hummingbird price/weight slider reads {$language.is_rtl} to set `data-slider-direction` - received no `language` at all.
Assign the language alongside the other facet variables, as an ARRAY mirroring the global `language` the front controller assigns via ObjectPresenter. The template accesses it with Smarty array syntax ({$language.is_rtl}), so the value must be an array: passing the raw Language object would raise a fatal "Cannot use object of type Language as array" on PHP 8. The default (classic) theme is unaffected as it does not read `language` in this template.
Fixes #41846.
36f5df2 to
9df4518
Compare
|
Thanks @SiraDIOP, and apologies for the regression — you are right, good catch. Assigning the raw I have pushed a fix (9df4518): Verified:
Could you re-test on Hummingbird when you have a moment? Thanks again for catching this. |
|
PR merged, well done! Message to @PrestaShop/committers: do not forget to milestone it before the merge. |


renderFacets()never assignedlanguageto Smarty, so theme overrides that read it (Hummingbird's price/weight slider uses{$language.is_rtl}fordata-slider-direction) get a nulllanguageand Smarty raises "offset on value of type null". This assigns the context language alongside the other facet variables.Description
SearchProvider::renderFacets()assigns the facet variables to Smarty but never assignslanguage. Themes that overridefacets.tpland reference the language break as a result: the Hummingbird price/weight slider uses{$language.is_rtl}to setdata-slider-direction, so on that theme$languageisnulland Smarty raises:in
facets.tpl.php(around line 491), which breaks the faceted-search block (reported on thedevelopPrestaShop branch with the Hummingbird theme).The fix assigns the context language alongside the other facet variables so the template — and any theme override — can read it safely. The default (classic) theme is unaffected because it does not reference
$languagein this template.How to test
offset on value of type nullerror.Unit test:
SearchProviderTestassertsrenderFacets()now assignslanguage(3 tests, 40 assertions, green; reverting the source change makes the test fail).