From 443f739b5c24a63c76e4506f1e8b2cbab839d5fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20FOUCRET?= Date: Fri, 31 Aug 2018 09:59:38 +0200 Subject: [PATCH] Remove facets when all options are the same for each products. --- .../Model/Layer/Filter/Attribute.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/module-elasticsuite-catalog/Model/Layer/Filter/Attribute.php b/src/module-elasticsuite-catalog/Model/Layer/Filter/Attribute.php index 71d14b13f..09b5cda5c 100644 --- a/src/module-elasticsuite-catalog/Model/Layer/Filter/Attribute.php +++ b/src/module-elasticsuite-catalog/Model/Layer/Filter/Attribute.php @@ -142,7 +142,6 @@ protected function _getItemsData() { /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */ $productCollection = $this->getLayer()->getProductCollection(); - $optionsFacetedData = $productCollection->getFacetedData($this->getFilterField()); $items = []; @@ -152,12 +151,16 @@ protected function _getItemsData() unset($optionsFacetedData['__other_docs']); } - foreach ($optionsFacetedData as $value => $data) { - $items[$value] = [ - 'label' => $this->tagFilter->filter($value), - 'value' => $value, - 'count' => $data['count'], - ]; + $minCount = !empty($optionsFacetedData) ? min(array_column($optionsFacetedData, 'count')) : 0; + + if (!empty($this->currentFilterValue) || $minCount < $productCollection->getSize()) { + foreach ($optionsFacetedData as $value => $data) { + $items[$value] = [ + 'label' => $this->tagFilter->filter($value), + 'value' => $value, + 'count' => $data['count'], + ]; + } } $items = $this->addOptionsData($items);