diff --git a/ps_facetedsearch.php b/ps_facetedsearch.php index df2f639b3..976d75140 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_INDEX_COUNTRIES', 1); $this->psLayeredFullTree = 1; @@ -400,6 +401,8 @@ public function indexProductPrices($idProduct, $smart = true) } } + $index_countries = (bool) Configuration::get('PS_LAYERED_INDEX_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 . ' ' . + ($index_countries ? '' : 'AND c.id_country = 0 ') . '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 ($index_countries) { + $shopCountries = Country::getCountriesByIdShop($idShop, $this->getContext()->language->id); + } else { + $shopCountries = [[ + 'id_country' => 0, + 'active' => 1, + 'iso_code' => '', + ]]; + } + $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 ($index_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_INDEX_COUNTRIES', (int) Tools::getValue('ps_layered_index_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'), + '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 8af448ce0..12eaab86f 100644 --- a/src/Adapter/MySQL.php +++ b/src/Adapter/MySQL.php @@ -161,6 +161,14 @@ protected function getFieldMapping() 'sa' ); + $index_countries = (bool) Configuration::get('PS_LAYERED_INDEX_COUNTRIES'); + + if (!$index_countries) { + $countryCondition = ' AND psi.id_country = ' . (int) Configuration::get('PS_COUNTRY_DEFAULT'); + } else { + $countryCondition = ' AND psi.id_country = 0'; + } + $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' => [ @@ -320,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 @@
- +