From 46a916a52b3352d979635b997940731e3da193e0 Mon Sep 17 00:00:00 2001 From: Markus-Gurkcity Date: Mon, 4 May 2026 13:31:47 +0200 Subject: [PATCH 1/2] product price indexation omit country --- ps_facetedsearch.php | 24 ++++++++++++++++++++++-- src/Adapter/MySQL.php | 16 ++++++++++++---- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/ps_facetedsearch.php b/ps_facetedsearch.php index df2f639b3..b3392782b 100644 --- a/ps_facetedsearch.php +++ b/ps_facetedsearch.php @@ -210,6 +210,7 @@ public function install() Configuration::updateValue('PS_LAYERED_FILTER_BY_DEFAULT_CATEGORY', 0); Configuration::updateValue('PS_USE_JQUERY_UI_SLIDER', 1); Configuration::updateValue('PS_LAYERED_DEFAULT_CATEGORY_TEMPLATE', 0); + Configuration::updateValue('PS_LAYERED_OMIT_COUNTRIES', 0); $this->psLayeredFullTree = 1; @@ -400,6 +401,8 @@ public function indexProductPrices($idProduct, $smart = true) } } + $omit_countries = (bool) Configuration::get('PS_LAYERED_OMIT_COUNTRIES'); + $shopList = Shop::getShops(false, null, true); foreach ($shopList as $idShop) { @@ -421,11 +424,21 @@ public function indexProductPrices($idProduct, $smart = true) 'LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.id_tax = tr.id_tax AND t.active = 1) ' . 'JOIN `' . _DB_PREFIX_ . 'country` c ON (tr.id_country=c.id_country AND c.active = 1) ' . 'WHERE id_product = ' . (int) $idProduct . ' ' . + ($omit_countries ? 'AND c.id_country = ' . (int) Configuration::get('PS_COUNTRY_DEFAULT') : '') . ' ' . 'GROUP BY id_product, tr.id_country' ); if (empty($taxRatesByCountry) || !Configuration::get('PS_LAYERED_FILTER_PRICE_USETAX')) { - $shopCountries = Country::getCountriesByIdShop($idShop, $this->getContext()->language->id); + if ($omit_countries) { + $shopCountries = [[ + 'id_country' => (int) Configuration::get('PS_COUNTRY_DEFAULT'), + 'active' => 1, + 'iso_code' => Country::getIsoById((int) Configuration::get('PS_COUNTRY_DEFAULT')), + ]]; + } else { + $shopCountries = Country::getCountriesByIdShop($idShop, $this->getContext()->language->id); + } + $taxCountries = array_filter($shopCountries, function ($country) { return $country['active']; }); @@ -444,7 +457,12 @@ public function indexProductPrices($idProduct, $smart = true) WHERE id_product = ' . (int) $idProduct . ' AND id_shop IN (0,' . (int) $idShop . ')' ); - $countries = Country::getCountries($this->getContext()->language->id, true, false, false); + if ($omit_countries) { + $countries = [['id_country' => (int) Configuration::get('PS_COUNTRY_DEFAULT')]]; + } else { + $countries = Country::getCountries($this->getContext()->language->id, true, false, false); + } + foreach ($countries as $country) { $idCountry = $country['id_country']; @@ -713,6 +731,7 @@ public function getContent() Configuration::updateValue('PS_LAYERED_FILTER_BY_DEFAULT_CATEGORY', (int) Tools::getValue('ps_layered_filter_by_default_category')); Configuration::updateValue('PS_USE_JQUERY_UI_SLIDER', (int) Tools::getValue('ps_use_jquery_ui_slider')); Configuration::updateValue('PS_LAYERED_DEFAULT_CATEGORY_TEMPLATE', (int) Tools::getValue('ps_layered_default_category_template')); + Configuration::updateValue('PS_LAYERED_OMIT_COUNTRIES', (int) Tools::getValue('ps_layered_omit_countries')); $this->psLayeredFullTree = (int) Tools::getValue('ps_layered_full_tree'); @@ -809,6 +828,7 @@ public function renderAdminMain() 'filter_by_default_category' => (bool) Configuration::get('PS_LAYERED_FILTER_BY_DEFAULT_CATEGORY'), 'use_jquery_ui_slider' => (bool) Configuration::get('PS_USE_JQUERY_UI_SLIDER'), 'default_category_template' => Configuration::get('PS_LAYERED_DEFAULT_CATEGORY_TEMPLATE'), + 'omit_countries' => Configuration::get('PS_LAYERED_OMIT_COUNTRIES'), ]); return $this->display(__FILE__, 'views/templates/admin/manage.tpl'); diff --git a/src/Adapter/MySQL.php b/src/Adapter/MySQL.php index 8af448ce0..a7212acfe 100644 --- a/src/Adapter/MySQL.php +++ b/src/Adapter/MySQL.php @@ -161,6 +161,14 @@ protected function getFieldMapping() 'sa' ); + $omit_countries = (bool) Configuration::get('PS_LAYERED_OMIT_COUNTRIES'); + + if (!$omit_countries) { + $countryCondition = ' AND psi.id_country = ' . $this->getContext()->country->id; + } else { + $countryCondition = ' AND psi.id_country = ' . (int) Configuration::get('PS_COUNTRY_DEFAULT'); + } + $filterToTableMapping = [ 'id_product_attribute' => [ 'tableName' => 'product_attribute', @@ -277,28 +285,28 @@ protected function getFieldMapping() 'tableName' => 'layered_price_index', 'tableAlias' => 'psi', 'joinCondition' => '(psi.id_product = p.id_product AND psi.id_shop = ' . $this->getContext()->shop->id . ' AND psi.id_currency = ' . - $this->getContext()->currency->id . ' AND psi.id_country = ' . $this->getContext()->country->id . ')', + $this->getContext()->currency->id . $countryCondition . ')', 'joinType' => self::INNER_JOIN, ], 'price_max' => [ 'tableName' => 'layered_price_index', 'tableAlias' => 'psi', 'joinCondition' => '(psi.id_product = p.id_product AND psi.id_shop = ' . $this->getContext()->shop->id . ' AND psi.id_currency = ' . - $this->getContext()->currency->id . ' AND psi.id_country = ' . $this->getContext()->country->id . ')', + $this->getContext()->currency->id . $countryCondition . ')', 'joinType' => self::INNER_JOIN, ], 'range_start' => [ 'tableName' => 'layered_price_index', 'tableAlias' => 'psi', 'joinCondition' => '(psi.id_product = p.id_product AND psi.id_shop = ' . $this->getContext()->shop->id . ' AND psi.id_currency = ' . - $this->getContext()->currency->id . ' AND psi.id_country = ' . $this->getContext()->country->id . ')', + $this->getContext()->currency->id . $countryCondition . ')', 'joinType' => self::INNER_JOIN, ], 'range_end' => [ 'tableName' => 'layered_price_index', 'tableAlias' => 'psi', 'joinCondition' => '(psi.id_product = p.id_product AND psi.id_shop = ' . $this->getContext()->shop->id . ' AND psi.id_currency = ' . - $this->getContext()->currency->id . ' AND psi.id_country = ' . $this->getContext()->country->id . ')', + $this->getContext()->currency->id . $countryCondition . ')', 'joinType' => self::INNER_JOIN, ], 'id_group' => [ From f7a7b7d02ae2ec1f282f859cc5aa6324ec042235 Mon Sep 17 00:00:00 2001 From: Markus-Gurkcity Date: Tue, 23 Jun 2026 09:23:46 +0200 Subject: [PATCH 2/2] reverse condition fron omit countries to index countries --- ps_facetedsearch.php | 22 +++++++++++----------- src/Adapter/MySQL.php | 24 ++++++++++++------------ upgrade/upgrade-4.0.4.php | 2 ++ views/templates/admin/manage.tpl | 24 +++++++++++++++++++++++- 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/ps_facetedsearch.php b/ps_facetedsearch.php index b3392782b..976d75140 100644 --- a/ps_facetedsearch.php +++ b/ps_facetedsearch.php @@ -210,7 +210,7 @@ public function install() Configuration::updateValue('PS_LAYERED_FILTER_BY_DEFAULT_CATEGORY', 0); Configuration::updateValue('PS_USE_JQUERY_UI_SLIDER', 1); Configuration::updateValue('PS_LAYERED_DEFAULT_CATEGORY_TEMPLATE', 0); - Configuration::updateValue('PS_LAYERED_OMIT_COUNTRIES', 0); + Configuration::updateValue('PS_LAYERED_INDEX_COUNTRIES', 1); $this->psLayeredFullTree = 1; @@ -401,7 +401,7 @@ public function indexProductPrices($idProduct, $smart = true) } } - $omit_countries = (bool) Configuration::get('PS_LAYERED_OMIT_COUNTRIES'); + $index_countries = (bool) Configuration::get('PS_LAYERED_INDEX_COUNTRIES'); $shopList = Shop::getShops(false, null, true); @@ -424,19 +424,19 @@ public function indexProductPrices($idProduct, $smart = true) 'LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.id_tax = tr.id_tax AND t.active = 1) ' . 'JOIN `' . _DB_PREFIX_ . 'country` c ON (tr.id_country=c.id_country AND c.active = 1) ' . 'WHERE id_product = ' . (int) $idProduct . ' ' . - ($omit_countries ? 'AND c.id_country = ' . (int) Configuration::get('PS_COUNTRY_DEFAULT') : '') . ' ' . + ($index_countries ? '' : 'AND c.id_country = 0 ') . 'GROUP BY id_product, tr.id_country' ); if (empty($taxRatesByCountry) || !Configuration::get('PS_LAYERED_FILTER_PRICE_USETAX')) { - if ($omit_countries) { + if ($index_countries) { + $shopCountries = Country::getCountriesByIdShop($idShop, $this->getContext()->language->id); + } else { $shopCountries = [[ - 'id_country' => (int) Configuration::get('PS_COUNTRY_DEFAULT'), + 'id_country' => 0, 'active' => 1, - 'iso_code' => Country::getIsoById((int) Configuration::get('PS_COUNTRY_DEFAULT')), + 'iso_code' => '', ]]; - } else { - $shopCountries = Country::getCountriesByIdShop($idShop, $this->getContext()->language->id); } $taxCountries = array_filter($shopCountries, function ($country) { @@ -457,7 +457,7 @@ public function indexProductPrices($idProduct, $smart = true) WHERE id_product = ' . (int) $idProduct . ' AND id_shop IN (0,' . (int) $idShop . ')' ); - if ($omit_countries) { + if ($index_countries) { $countries = [['id_country' => (int) Configuration::get('PS_COUNTRY_DEFAULT')]]; } else { $countries = Country::getCountries($this->getContext()->language->id, true, false, false); @@ -731,7 +731,7 @@ public function getContent() Configuration::updateValue('PS_LAYERED_FILTER_BY_DEFAULT_CATEGORY', (int) Tools::getValue('ps_layered_filter_by_default_category')); Configuration::updateValue('PS_USE_JQUERY_UI_SLIDER', (int) Tools::getValue('ps_use_jquery_ui_slider')); Configuration::updateValue('PS_LAYERED_DEFAULT_CATEGORY_TEMPLATE', (int) Tools::getValue('ps_layered_default_category_template')); - Configuration::updateValue('PS_LAYERED_OMIT_COUNTRIES', (int) Tools::getValue('ps_layered_omit_countries')); + Configuration::updateValue('PS_LAYERED_INDEX_COUNTRIES', (int) Tools::getValue('ps_layered_index_countries')); $this->psLayeredFullTree = (int) Tools::getValue('ps_layered_full_tree'); @@ -828,7 +828,7 @@ public function renderAdminMain() 'filter_by_default_category' => (bool) Configuration::get('PS_LAYERED_FILTER_BY_DEFAULT_CATEGORY'), 'use_jquery_ui_slider' => (bool) Configuration::get('PS_USE_JQUERY_UI_SLIDER'), 'default_category_template' => Configuration::get('PS_LAYERED_DEFAULT_CATEGORY_TEMPLATE'), - 'omit_countries' => Configuration::get('PS_LAYERED_OMIT_COUNTRIES'), + 'index_countries' => (bool) Configuration::get('PS_LAYERED_INDEX_COUNTRIES'), ]); return $this->display(__FILE__, 'views/templates/admin/manage.tpl'); diff --git a/src/Adapter/MySQL.php b/src/Adapter/MySQL.php index a7212acfe..12eaab86f 100644 --- a/src/Adapter/MySQL.php +++ b/src/Adapter/MySQL.php @@ -161,12 +161,12 @@ protected function getFieldMapping() 'sa' ); - $omit_countries = (bool) Configuration::get('PS_LAYERED_OMIT_COUNTRIES'); + $index_countries = (bool) Configuration::get('PS_LAYERED_INDEX_COUNTRIES'); - if (!$omit_countries) { - $countryCondition = ' AND psi.id_country = ' . $this->getContext()->country->id; - } else { + if (!$index_countries) { $countryCondition = ' AND psi.id_country = ' . (int) Configuration::get('PS_COUNTRY_DEFAULT'); + } else { + $countryCondition = ' AND psi.id_country = 0'; } $filterToTableMapping = [ @@ -328,17 +328,17 @@ protected function getFieldMapping() 'tableName' => 'specific_price', 'tableAlias' => 'sp', 'joinCondition' => '( - sp.id_product = p.id_product AND - sp.id_shop IN (0, ' . $this->getContext()->shop->id . ') AND - sp.id_currency IN (0, ' . $this->getContext()->currency->id . ') AND - sp.id_country IN (0, ' . $this->getContext()->country->id . ') AND - sp.id_group IN (0, ' . $this->getContext()->customer->id_default_group . ') AND + sp.id_product = p.id_product AND + sp.id_shop IN (0, ' . $this->getContext()->shop->id . ') AND + sp.id_currency IN (0, ' . $this->getContext()->currency->id . ') AND + sp.id_country IN (0, ' . $this->getContext()->country->id . ') AND + sp.id_group IN (0, ' . $this->getContext()->customer->id_default_group . ') AND sp.from_quantity = 1 AND sp.reduction > 0 AND sp.id_customer = 0 AND - sp.id_cart = 0 AND - (sp.from = \'0000-00-00 00:00:00\' OR \'' . date('Y-m-d H:i:s') . '\' >= sp.from) AND - (sp.to = \'0000-00-00 00:00:00\' OR \'' . date('Y-m-d H:i:s') . '\' <= sp.to) + sp.id_cart = 0 AND + (sp.from = \'0000-00-00 00:00:00\' OR \'' . date('Y-m-d H:i:s') . '\' >= sp.from) AND + (sp.to = \'0000-00-00 00:00:00\' OR \'' . date('Y-m-d H:i:s') . '\' <= sp.to) )', 'joinType' => self::LEFT_JOIN, ], diff --git a/upgrade/upgrade-4.0.4.php b/upgrade/upgrade-4.0.4.php index abf9aed48..a81019a9f 100644 --- a/upgrade/upgrade-4.0.4.php +++ b/upgrade/upgrade-4.0.4.php @@ -26,5 +26,7 @@ function upgrade_module_4_0_4(Ps_Facetedsearch $module) // Change data column to longtext Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . 'layered_filter_block` CHANGE `data` `data` LONGTEXT NULL;'); + Configuration::updateValue('PS_LAYERED_INDEX_COUNTRIES', 1); + return true; } diff --git a/views/templates/admin/manage.tpl b/views/templates/admin/manage.tpl index 10129f7ed..b584b68dd 100644 --- a/views/templates/admin/manage.tpl +++ b/views/templates/admin/manage.tpl @@ -211,6 +211,28 @@ +
+ +
+ + + + + + + +
+
+
+ {l s='Index prices by countries option allows you to enable or disable the indexing of prices for different countries in the layered navigation filters. Turn this off when you do not need country-specific pricing.' d='Modules.Facetedsearch.Admin'} +
+
+
+
@@ -285,7 +307,7 @@
- +