Skip to content

Commit

Permalink
Minor fixes, change version
Browse files Browse the repository at this point in the history
  • Loading branch information
Hlavtox committed Aug 3, 2023
1 parent 93017eb commit 457d2f0
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>ps_facetedsearch</name>
<displayName><![CDATA[Faceted search]]></displayName>
<version><![CDATA[3.13.1]]></version>
<version><![CDATA[3.14.0]]></version>
<description><![CDATA[Displays a block allowing multiple filters.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[front_office_features]]></tab>
Expand Down
5 changes: 2 additions & 3 deletions ps_facetedsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function __construct()
{
$this->name = 'ps_facetedsearch';
$this->tab = 'front_office_features';
$this->version = '3.13.1';
$this->version = '3.14.0';
$this->author = 'PrestaShop';
$this->need_instance = 0;
$this->bootstrap = true;
Expand Down Expand Up @@ -594,7 +594,6 @@ public function indexProductPrices($idProduct, $smart = true)
*/
public function getContent()
{
global $cookie;
$message = '';

if (Tools::isSubmit('SubmitFilter')) {
Expand Down Expand Up @@ -1197,7 +1196,7 @@ public function rebuildLayeredCache($productsIds = [], $categoriesIds = [], $reb

if (!isset($doneCategories[(int) $idCategory]['q'])) {
$filterData['layered_selection_highlights'] = ['filter_type' => Converter::WIDGET_TYPE_CHECKBOX, 'filter_show_limit' => 0];
$doneCategories[(int) $idCategory]['e'] = true;
$doneCategories[(int) $idCategory]['h'] = true;
$toInsert = true;
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/Adapter/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,11 @@ public function valueCount($fieldName = null)
*/
public function useFiltersAsInitialPopulation()
{
// Initial population has NO LIMIT and no ORDER BY
$this->setLimit(null);
$this->setOrderField('');

// We add basic select fields we will need to matter what
$this->setSelectFields(
[
'id_product',
Expand All @@ -796,9 +799,14 @@ public function useFiltersAsInitialPopulation()
'price',
'sales',
'on_sale',
'date_add',
]
);

// Clone it, add it to initial population
$this->initialPopulation = clone $this;

// Reset all filters so we start clean and add only the base select, we don't need anything else
$this->resetAll();
$this->addSelectField('id_product');
}
Expand Down
1 change: 1 addition & 0 deletions src/Filters/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ private function getHighlightsBlock($filter, $selectedFilters)
Search::HIGHLIGHTS_FILTER,
[[['on_sale', [1], '=']]]
);
$filteredSearchAdapter->getInitialPopulation()->addSelectField('on_sale');
$highlightsOptions['sale']['nbr'] = $filteredSearchAdapter->count();

// New products - available everywhere except that page
Expand Down
4 changes: 2 additions & 2 deletions src/Filters/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public function createFacetedSearchFiltersFromQuery(ProductSearchQuery $query)
}
break;
case self::TYPE_HIGHLIGHTS:
if (!isset($facetAndFiltersLabels[$filterLabel])) {
if (!isset($receivedFilters[$filterLabel])) {
// No need to filter if no information
continue 2;
}
Expand All @@ -379,7 +379,7 @@ public function createFacetedSearchFiltersFromQuery(ProductSearchQuery $query)

$searchFilters[$filter['type']] = [];
foreach ($highlightsOptions as $highlightsOption => $optionId) {
if (isset($facetAndFiltersLabels[$filterLabel]) && in_array($highlightsOption, $facetAndFiltersLabels[$filterLabel])) {
if (isset($receivedFilters[$filterLabel]) && in_array($highlightsOption, $receivedFilters[$filterLabel])) {
$searchFilters[$filter['type']][] = $optionId;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Product/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ public function initSearch($selectedFilters)
// Adds filters that specific for this controller
$this->addControllerSpecificFilters();

// Add group by and flush it, let's go
// Add group by to remove duplicate values
$this->getSearchAdapter()->addGroupBy('id_product');

// Move the current search into the "initialPopulation"
// This initialPopulation will be used to generate the base table in the final query
$this->getSearchAdapter()->useFiltersAsInitialPopulation();
}

Expand Down
16 changes: 5 additions & 11 deletions src/Product/SearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,7 @@ private function hideUselessFacets(array $facets, $totalProducts)
continue;
}

// We won't apply this to availability facet, let's keep the value displayed
// Don't worry, the facet will be hidden if there are no values with products
if ($facet->getType() == 'availability' || $facet->getType() == 'highlights') {
continue;
}

// Now the rest of facets - we apply this logic
$totalFacetProducts = 0;
$usefulFiltersCount = 0;
foreach ($facet->getFilters() as $filter) {
Expand All @@ -542,16 +537,15 @@ private function hideUselessFacets(array $facets, $totalProducts)
// There are two filters displayed
$usefulFiltersCount > 1
||
/*
* There is only one fitler and the
* magnitude is different than the
* total products
*/
// There is only one filter, but it reduces the product selection
(
count($facet->getFilters()) === 1
&& $totalFacetProducts < $totalProducts
&& $usefulFiltersCount > 0
)
||
// There is only one filter, but it's availability or highlights
($usefulFiltersCount === 1 && ($facet->getType() == 'availability' || $facet->getType() == 'highlights'))
);
}
}
Expand Down
5 changes: 0 additions & 5 deletions upgrade/upgrade-3.13.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@

function upgrade_module_3_13_0(Ps_Facetedsearch $module)
{
// Add new filter type into database
Db::getInstance()->execute(
'ALTER TABLE `' . _DB_PREFIX_ . 'layered_category`
CHANGE `type` `type` ENUM(\'category\',\'id_feature\',\'id_attribute_group\',\'availability\',\'condition\',\'manufacturer\',\'weight\',\'price\',\'highlights\') NOT NULL;');

$newHooks = [
'actionFeatureValueFormBuilderModifier',
'actionAfterCreateFeatureValueFormHandler',
Expand Down

0 comments on commit 457d2f0

Please sign in to comment.