From 9df4518afeb6d2aa96c4843d264e51bd764f835c Mon Sep 17 00:00:00 2001 From: Audrius Date: Fri, 26 Jun 2026 11:15:18 +0200 Subject: [PATCH] Assign language to the facets template so theme overrides can read it 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. --- src/Product/SearchProvider.php | 19 +++++++++++ .../Product/SearchProviderTest.php | 32 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/Product/SearchProvider.php b/src/Product/SearchProvider.php index 6ad576f2e..f4c65ab69 100644 --- a/src/Product/SearchProvider.php +++ b/src/Product/SearchProvider.php @@ -301,9 +301,28 @@ public function renderFacets(ProductSearchContext $context, ProductSearchResult return ''; } + $language = $this->module->getContext()->language; + $this->module->getContext()->smarty->assign( [ 'show_quantities' => Configuration::get('PS_LAYERED_SHOW_QTIES'), + // Provide the language to the template so theme overrides can read it (e.g. the + // Hummingbird slider uses {$language.is_rtl} for the slider direction). It must be + // an ARRAY, mirroring the global `language` the front controller assigns (via + // ObjectPresenter), because the template accesses it with Smarty array syntax + // ({$language.is_rtl}); passing the Language object would make that a fatal + // "Cannot use object of type Language as array". (#41846) + 'language' => [ + 'id' => (int) $language->id, + 'name' => $language->name, + 'iso_code' => $language->iso_code, + 'locale' => $language->locale, + 'language_code' => $language->language_code, + 'active' => $language->active, + 'is_rtl' => $language->is_rtl, + 'date_format_lite' => $language->date_format_lite, + 'date_format_full' => $language->date_format_full, + ], 'facets' => $facetsVar, 'js_enabled' => $this->module->isAjax(), 'displayedFacets' => $displayedFacets, diff --git a/tests/php/FacetedSearch/Product/SearchProviderTest.php b/tests/php/FacetedSearch/Product/SearchProviderTest.php index a9adba7c0..4dda82a99 100644 --- a/tests/php/FacetedSearch/Product/SearchProviderTest.php +++ b/tests/php/FacetedSearch/Product/SearchProviderTest.php @@ -115,6 +115,16 @@ protected function setUp() { $this->database = Mockery::mock(Db::class); $this->context = Mockery::mock(Context::class); + $this->context->language = Mockery::mock(\Language::class); + $this->context->language->id = 1; + $this->context->language->name = 'English (English)'; + $this->context->language->iso_code = 'en'; + $this->context->language->locale = 'en-US'; + $this->context->language->language_code = 'en-us'; + $this->context->language->active = true; + $this->context->language->is_rtl = false; + $this->context->language->date_format_lite = 'Y-m-d'; + $this->context->language->date_format_full = 'Y-m-d H:i:s'; $this->converter = Mockery::mock(Converter::class); $this->serializer = Mockery::mock(URLSerializer::class); $this->facetCollection = Mockery::mock(FacetCollection::class); @@ -181,6 +191,17 @@ public function testRenderFacetsWithFacetsCollection() ->with( [ 'show_quantities' => true, + 'language' => [ + 'id' => 1, + 'name' => 'English (English)', + 'iso_code' => 'en', + 'locale' => 'en-US', + 'language_code' => 'en-us', + 'active' => true, + 'is_rtl' => false, + 'date_format_lite' => 'Y-m-d', + 'date_format_full' => 'Y-m-d H:i:s', + ], 'facets' => [ [ 'filters' => [], @@ -240,6 +261,17 @@ public function testRenderFacetsWithFacetsCollectionAndFilters() ->with( [ 'show_quantities' => true, + 'language' => [ + 'id' => 1, + 'name' => 'English (English)', + 'iso_code' => 'en', + 'locale' => 'en-US', + 'language_code' => 'en-us', + 'active' => true, + 'is_rtl' => false, + 'date_format_lite' => 'Y-m-d', + 'date_format_full' => 'Y-m-d H:i:s', + ], 'facets' => [ [ 'displayed' => true,