Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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_INDEX_COUNTRIES', 1);

$this->psLayeredFullTree = 1;

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

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_INDEX_COUNTRIES', (int) Tools::getValue('ps_layered_index_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'),
'index_countries' => (bool) Configuration::get('PS_LAYERED_INDEX_COUNTRIES'),
]);

return $this->display(__FILE__, 'views/templates/admin/manage.tpl');
Expand Down
32 changes: 20 additions & 12 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'
);

$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',
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 All @@ -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,
],
Expand Down
2 changes: 2 additions & 0 deletions upgrade/upgrade-4.0.4.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
24 changes: 23 additions & 1 deletion views/templates/admin/manage.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,28 @@
</div>
</div>

<div class="form-group">
<label class="col-lg-3 control-label">{l s='Index prices by countries' d='Modules.Facetedsearch.Admin'}</label>
<div class="col-lg-9">
<span class="switch prestashop-switch fixed-width-lg">
<input type="radio" name="ps_layered_filter_index_countries" id="ps_layered_filter_index_countries_on" value="1"{if $index_countries} checked="checked"{/if}>
<label for="ps_layered_filter_index_countries_on" class="radioCheck">
<i class="color_success"></i> {l s='Yes' d='Admin.Global'}
</label>
<input type="radio" name="ps_layered_filter_index_countries" id="ps_layered_filter_index_countries_off" value="0"{if !$index_countries} checked="checked"{/if}>
<label for="ps_layered_filter_index_countries_off" class="radioCheck">
<i class="color_danger"></i> {l s='No' d='Admin.Global'}
</label>
<a class="slide-button btn"></a>
</span>
</div>
<div class="col-lg-9 col-lg-offset-3">
<div class="help-block">
{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'}
</div>
</div>
</div>

<div class="form-group">
<label class="col-lg-3 control-label">{l s='Use tax to filter price' d='Modules.Facetedsearch.Admin'}</label>
<div class="col-lg-9">
Expand Down Expand Up @@ -285,7 +307,7 @@
</div>

<div class="form-group">
<label class="control-label col-lg-3">{l s='Default filter template for new categories' d='Modules.Facetedsearch.Admin'}</label>
<label class="control-label col-lg-3">{l s='Default filter template for new categories' d='Modules.Facetedsearch.Admin'}</label>
<div class="col-lg-9">
<select class="form-control fixed-width-xxl" name="ps_layered_default_category_template" id="ps_layered_default_category_template">
<option value="0" {if empty($default_category_template)} selected="selected" {/if}>{l s='None' d='Admin.Global'}</option>
Expand Down
Loading