Skip to content

Commit

Permalink
suppress php mess detector warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
androshchuk committed Jun 21, 2019
1 parent 1129ec8 commit 1be6972
Showing 1 changed file with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
*/
private $originalPageSize = false;

/**
* @var array
*/
private $countByAttributeSet;
/**
* @var array
*/
private $countByAttributeCode;

/**
* Constructor.
*
Expand Down Expand Up @@ -182,7 +191,7 @@ public function __construct(
public function getSize()
{
if ($this->_totalRecords === null) {
$this->load();
$this->loadProductCounts();
}

return $this->_totalRecords;
Expand Down Expand Up @@ -463,6 +472,54 @@ protected function _afterLoad()
return parent::_afterLoad();
}

/**
* Load product count :
* - collection size
* - number of products by attribute set (legacy)
* - number of products by attribute code
*
* @return void
*/
private function loadProductCounts(): void
{
$storeId = $this->getStoreId();
$requestName = $this->searchRequestName;
$facets = [
['name' => 'attribute_set_id', 'type' => BucketInterface::TYPE_TERM, 'size' => 0],
['name' => 'indexed_attributes', 'type' => BucketInterface::TYPE_TERM, 'size' => 0],
];
$searchRequest = $this->requestBuilder->create(
$storeId,
$requestName,
0,
0,
$this->query,
[],
$this->filters,
$this->queryFilters,
$facets
);
$searchResponse = $this->searchEngine->search($searchRequest);
$this->_totalRecords = $searchResponse->count();
$this->countByAttributeSet = [];
$this->countByAttributeCode = [];
$this->isSpellchecked = $searchRequest->isSpellchecked();
$attributeSetIdBucket = $searchResponse->getAggregations()->getBucket('attribute_set_id');
$attributeCodeBucket = $searchResponse->getAggregations()->getBucket('indexed_attributes');
if ($attributeSetIdBucket) {
foreach ($attributeSetIdBucket->getValues() as $value) {
$metrics = $value->getMetrics();
$this->countByAttributeSet[$value->getValue()] = $metrics['count'];
}
}
if ($attributeCodeBucket) {
foreach ($attributeCodeBucket->getValues() as $value) {
$metrics = $value->getMetrics();
$this->countByAttributeCode[$value->getValue()] = $metrics['count'];
}
}
}

/**
* Prepare the search request before it will be executed.
*
Expand Down

0 comments on commit 1be6972

Please sign in to comment.