Skip to content

Commit

Permalink
Merge pull request #1051 from afoucret/remove-irrelant-facets
Browse files Browse the repository at this point in the history
Remove facets when all options are the same for each products.
  • Loading branch information
afoucret authored Aug 31, 2018
2 parents 21d21fe + 443f739 commit 3fe6454
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/module-elasticsuite-catalog/Model/Layer/Filter/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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);
Expand Down

0 comments on commit 3fe6454

Please sign in to comment.