Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use feature value position for ordering #1083

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions ps_facetedsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ public function install()
}
}

Configuration::updateValue('PS_LAYERED_FILTER_FEATURE_VALUES_USE_POSITION', 0);

return true;
}

Expand All @@ -247,6 +249,7 @@ public function uninstall()
Configuration::deleteByName('PS_LAYERED_FILTER_PRICE_ROUNDING');
Configuration::deleteByName('PS_LAYERED_FILTER_SHOW_OUT_OF_STOCK_LAST');
Configuration::deleteByName('PS_LAYERED_FILTER_BY_DEFAULT_CATEGORY');
Configuration::deleteByName('PS_LAYERED_FILTER_FEATURE_VALUES_USE_POSITION');

$this->getDatabase()->execute('DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'layered_category');
$this->getDatabase()->execute('DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'layered_filter');
Expand Down Expand Up @@ -713,6 +716,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_FILTER_FEATURE_VALUES_USE_POSITION', (int) Tools::getValue('ps_layered_filter_feature_values_use_position'));

$this->psLayeredFullTree = (int) Tools::getValue('ps_layered_full_tree');

Expand Down Expand Up @@ -805,6 +809,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'),
'feature_values_use_position' => (bool) Configuration::get('PS_LAYERED_FILTER_FEATURE_VALUES_USE_POSITION'),
]);

return $this->display(__FILE__, 'views/templates/admin/manage.tpl');
Expand Down
10 changes: 9 additions & 1 deletion src/Filters/DataAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace PrestaShop\Module\FacetedSearch\Filters;

use Configuration;
use Combination;
use Db;
use Shop;
Expand Down Expand Up @@ -191,6 +192,13 @@ public function getFeatureValues($idFeature, $idLang)
{
if (!isset($this->featureValues[$idLang][$idFeature])) {
$this->featureValues[$idLang] = [$idFeature => []];

if ((bool) Configuration::get('PS_LAYERED_FILTER_FEATURE_VALUES_USE_POSITION')) {
$order = 'ORDER BY v.`position` ASC';
} else {
$order = 'ORDER BY vl.`value` ASC';
}

$tempFeatureValues = $this->database->executeS(
'SELECT v.*, vl.*, ' .
'IF(lifvlv.`url_name` IS NULL OR lifvlv.`url_name` = "", NULL, lifvlv.`url_name`) AS url_name, ' .
Expand All @@ -201,7 +209,7 @@ public function getFeatureValues($idFeature, $idLang)
'LEFT JOIN `' . _DB_PREFIX_ . 'layered_indexable_feature_value_lang_value` lifvlv ' .
'ON (v.`id_feature_value` = lifvlv.`id_feature_value` AND lifvlv.`id_lang` = ' . (int) $idLang . ') ' .
'WHERE v.`id_feature` = ' . (int) $idFeature . ' ' .
'ORDER BY vl.`value` ASC'
$order
);

foreach ($tempFeatureValues as $feature) {
Expand Down
17 changes: 17 additions & 0 deletions views/templates/admin/manage.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,23 @@
</div>
</div>

<div class="form-group">
<label class="col-lg-3 control-label">{l s='Use position for feature values ordering' 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_feature_values_use_position" id="ps_layered_filter_feature_values_use_position_on" value="1"{if $feature_values_use_position} checked="checked"{/if}/>
<label for="ps_layered_filter_feature_values_use_position_on" class="radioCheck">
<i class="color_success"></i> {l s='Yes' d='Admin.Global'}
</label>
<input type="radio" name="ps_layered_filter_feature_values_use_position" id="ps_layered_filter_feature_values_use_position_off" value="0"{if !$feature_values_use_position} checked="checked"{/if}/>
<label for="ps_layered_filter_feature_values_use_position_off" class="radioCheck">
<i class="color_danger"></i> {l s='No' d='Admin.Global'}
</label>
<a class="slide-button btn"></a>
</span>
</div>
</div>

<div class="panel-footer">
<button type="submit" class="btn btn-default pull-right" name="submitLayeredSettings"><i class="process-icon-save"></i> {l s='Save' d='Admin.Actions'}</button>
</div>
Expand Down