Skip to content

Assign language to the facets template so theme overrides can read it#1257

Merged
mattgoud merged 1 commit into
PrestaShop:devfrom
boo-code:fix/assign-language-to-facets-template
Jul 6, 2026
Merged

Assign language to the facets template so theme overrides can read it#1257
mattgoud merged 1 commit into
PrestaShop:devfrom
boo-code:fix/assign-language-to-facets-template

Conversation

@boo-code

@boo-code boo-code commented Jun 26, 2026

Copy link
Copy Markdown
Contributor
Questions Answers
Description? renderFacets() never assigned language to Smarty, so theme overrides that read it (Hummingbird's price/weight slider uses {$language.is_rtl} for data-slider-direction) get a null language and Smarty raises "offset on value of type null". This assigns the context language alongside the other facet variables.
Type? bug fix
BC breaks? no
Deprecations? no
Fixed ticket? Fixes PrestaShop/PrestaShop#41846
How to test? See below.
Sponsor company

Description

SearchProvider::renderFacets() assigns the facet variables to Smarty but never assigns language. Themes that override facets.tpl and reference the language break as a result: the Hummingbird price/weight slider uses {$language.is_rtl} to set data-slider-direction, so on that theme $language is null and Smarty raises:

Trying to access array offset on value of type null

in facets.tpl.php (around line 491), which breaks the faceted-search block (reported on the develop PrestaShop 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 $language in this template.

How to test

  1. Use the Hummingbird theme with the faceted search module on a category page.
  2. Before the fix: the price/weight slider block triggers the Smarty offset on value of type null error.
  3. After the fix: the facets block renders with no error and the slider direction resolves from the shop language.

Unit test: SearchProviderTest asserts renderFacets() now assigns language (3 tests, 40 assertions, green; reverting the source change makes the test fail).

@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!

jolelievre
jolelievre previously approved these changes Jul 1, 2026

@jolelievre jolelievre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @boo-code

@ps-jarvis ps-jarvis added the Waiting for QA Status: Action required, Waiting for test feedback label Jul 1, 2026
@ps-jarvis ps-jarvis moved this from Ready for review to To be tested in PR Dashboard Jul 1, 2026
mattgoud
mattgoud previously approved these changes Jul 1, 2026
@SiraDIOP SiraDIOP self-assigned this Jul 1, 2026

@SiraDIOP SiraDIOP left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Image Image

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.
@boo-code
boo-code dismissed stale reviews from mattgoud and jolelievre via 9df4518 July 1, 2026 15:50
@boo-code
boo-code force-pushed the fix/assign-language-to-facets-template branch from 36f5df2 to 9df4518 Compare July 1, 2026 15:50
@boo-code

boo-code commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @SiraDIOP, and apologies for the regression — you are right, good catch. Assigning the raw Language object was my mistake: the template reads it with Smarty array syntax ({$language.is_rtl}), and Language (an ObjectModel) does not implement ArrayAccess, so on PHP 8 it throws the fatal you saw, turning the original warning into a hard error exactly as you reported.

I have pushed a fix (9df4518): renderFacets() now assigns language as an array, mirroring the language the front controller assigns globally via ObjectPresenter, so {$language.is_rtl} resolves as expected.

Verified:

  • Rendering {$language.is_rtl} with the raw object reproduces Cannot use object of type Language as array; with the array it renders (data-slider-direction="0" for an LTR language).
  • Updated SearchProviderTest; the full module suite is green (100 tests, 929 assertions).

Could you re-test on Hummingbird when you have a moment? Thanks again for catching this.

@SiraDIOP SiraDIOP left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @boo-code ,
Thanks for your PR. I retested it and it works fine for me, but I can't approve it until the code review is complete and the CI is green.

Image Image

Thanks

@mattgoud
mattgoud merged commit 59bcf24 into PrestaShop:dev Jul 6, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from To be tested to Merged in PR Dashboard Jul 6, 2026
@ps-jarvis

Copy link
Copy Markdown

PR merged, well done!

Message to @PrestaShop/committers: do not forget to milestone it before the merge.

@kpodemski kpodemski added QA ✔️ Status: Check done, Code approved and removed Waiting for QA Status: Action required, Waiting for test feedback labels Jul 6, 2026
@kpodemski kpodemski added this to the 5.0.0 milestone Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

QA ✔️ Status: Check done, Code approved

Projects

Status: Merged

Development

Successfully merging this pull request may close these issues.

ps_facetedsearch - Smarty error "offset on value of type null" on line 491 in facets.tpl.php on develop

7 participants