diff --git a/config.xml b/config.xml index 2eaac0173..e2426dd61 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ ps_facetedsearch - + diff --git a/ps_facetedsearch.php b/ps_facetedsearch.php index 2655b2951..d4f735985 100644 --- a/ps_facetedsearch.php +++ b/ps_facetedsearch.php @@ -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; @@ -594,7 +594,6 @@ public function indexProductPrices($idProduct, $smart = true) */ public function getContent() { - global $cookie; $message = ''; if (Tools::isSubmit('SubmitFilter')) { @@ -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; } } diff --git a/src/Adapter/MySQL.php b/src/Adapter/MySQL.php index 8714232bb..cc9fd5ea1 100644 --- a/src/Adapter/MySQL.php +++ b/src/Adapter/MySQL.php @@ -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', @@ -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'); } diff --git a/src/Filters/Block.php b/src/Filters/Block.php index 20f22c823..123a954e4 100644 --- a/src/Filters/Block.php +++ b/src/Filters/Block.php @@ -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 diff --git a/src/Filters/Converter.php b/src/Filters/Converter.php index 6033726b8..302d56d74 100644 --- a/src/Filters/Converter.php +++ b/src/Filters/Converter.php @@ -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; } @@ -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; } } diff --git a/src/Product/Search.php b/src/Product/Search.php index 08c6d0d98..673ea11a6 100644 --- a/src/Product/Search.php +++ b/src/Product/Search.php @@ -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(); } diff --git a/src/Product/SearchProvider.php b/src/Product/SearchProvider.php index 5b07ccd4e..9200fcb9e 100644 --- a/src/Product/SearchProvider.php +++ b/src/Product/SearchProvider.php @@ -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) { @@ -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')) ); } } diff --git a/upgrade/upgrade-3.13.0.php b/upgrade/upgrade-3.13.0.php index 8da2b02e9..516172a8c 100644 --- a/upgrade/upgrade-3.13.0.php +++ b/upgrade/upgrade-3.13.0.php @@ -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',