attributeSetFinder = $attributeSetFinder; $this->productAttributeRepository = $productAttributeRepository; $this->searchCriteriaBuilder = $searchCriteriaBuilder; $this->config = $config; $this->attributeCollection = $attributeCollection ?: \Magento\Framework\App\ObjectManager::getInstance()->get(AttributeCollection::class); $this->requestChecker = $aggregationChecker ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(RequestCheckerInterface::class); } /** * @inheritdoc */ public function resolve(RequestInterface $request, array $documentIds) { if (!$this->requestChecker->isApplicable($request)) { return []; } $data = $this->config->get($request->getName()); $bucketKeys = isset($data['aggregations']) ? array_keys($data['aggregations']) : []; $attributeCodes = $this->getApplicableAttributeCodes($documentIds); $resolvedAggregation = array_filter( $request->getAggregation(), function ($bucket) use ($attributeCodes, $bucketKeys) { /** @var BucketInterface $bucket */ return in_array($bucket->getField(), $attributeCodes, true) || in_array($bucket->getName(), $bucketKeys, true); } ); return array_values($resolvedAggregation); } /** * Get applicable attributes * * @param array $documentIds * @return array */ private function getApplicableAttributeCodes(array $documentIds) { $attributeSetIds = $this->attributeSetFinder->findAttributeSetIdsByProductIds($documentIds); $this->attributeCollection->setAttributeSetFilter($attributeSetIds); $this->attributeCollection->setEntityTypeFilter( \Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE ); $this->attributeCollection->getSelect() ->reset(\Magento\Framework\DB\Select::COLUMNS) ->columns('attribute_code'); return $this->attributeCollection->getConnection()->fetchCol($this->attributeCollection->getSelect()); } }