Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions ps_facetedsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -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'];
});
Expand All @@ -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'];

Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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');
Expand Down
16 changes: 12 additions & 4 deletions src/Adapter/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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' => [
Expand Down