From 982e6ae0b7401d5fc8790a208771f726f3151c78 Mon Sep 17 00:00:00 2001 From: Ilan Parmentier Date: Wed, 3 Oct 2018 17:22:04 +0200 Subject: [PATCH] Remove facets when all options are the same for each products. Related to this core issue : https://github.com/Smile-SA/elasticsuite/pull/1051 I have just applied what @afoucret done. Tell me if it is ok for you. Ilan PARMENTIER --- Model/Layer/Filter/Rating.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Model/Layer/Filter/Rating.php b/Model/Layer/Filter/Rating.php index 660e662..40a5385 100644 --- a/Model/Layer/Filter/Rating.php +++ b/Model/Layer/Filter/Rating.php @@ -120,14 +120,18 @@ protected function _getItemsData() } } krsort($optionsFacetedData); - - foreach ($optionsFacetedData as $value => $data) { - $sumCount += (int) $data['count']; - $items[$value] = [ - 'label' => $value, - 'value' => $value, - 'count' => $sumCount, - ]; + + $minCount = !empty($optionsFacetedData) ? min(array_column($optionsFacetedData, 'count')) : 0; + + if (!empty($this->currentFilterValue) || $minCount < $productCollection->getSize()) { + foreach ($optionsFacetedData as $value => $data) { + $sumCount += (int) $data['count']; + $items[$value] = [ + 'label' => $value, + 'value' => $value, + 'count' => $sumCount, + ]; + } } return $items;