Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getList($entityTypeCode, \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
 {
     if (!$entityTypeCode) {
         throw InputException::requiredField('entity_type_code');
     }
     /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $attributeCollection */
     $attributeCollection = $this->attributeCollectionFactory->create();
     $this->joinProcessor->process($attributeCollection);
     $attributeCollection->addFieldToFilter('entity_type_code', ['eq' => $entityTypeCode]);
     $attributeCollection->join(['entity_type' => $attributeCollection->getTable('eav_entity_type')], 'main_table.entity_type_id = entity_type.entity_type_id', []);
     $attributeCollection->joinLeft(['eav_entity_attribute' => $attributeCollection->getTable('eav_entity_attribute')], 'main_table.attribute_id = eav_entity_attribute.attribute_id', []);
     $entityType = $this->eavConfig->getEntityType($entityTypeCode);
     $additionalTable = $entityType->getAdditionalAttributeTable();
     if ($additionalTable) {
         $attributeCollection->join(['additional_table' => $attributeCollection->getTable($additionalTable)], 'main_table.attribute_id = additional_table.attribute_id', []);
     }
     //Add filters from root filter group to the collection
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $attributeCollection);
     }
     /** @var SortOrder $sortOrder */
     foreach ((array) $searchCriteria->getSortOrders() as $sortOrder) {
         $attributeCollection->addOrder($sortOrder->getField(), $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
     }
     $totalCount = $attributeCollection->getSize();
     // Group attributes by id to prevent duplicates with different attribute sets
     $attributeCollection->addAttributeGrouping();
     $attributeCollection->setCurPage($searchCriteria->getCurrentPage());
     $attributeCollection->setPageSize($searchCriteria->getPageSize());
     $attributes = [];
     /** @var \Magento\Eav\Api\Data\AttributeInterface $attribute */
     foreach ($attributeCollection as $attribute) {
         $attributes[] = $this->get($entityTypeCode, $attribute->getAttributeCode());
     }
     $searchResults = $this->searchResultsFactory->create();
     $searchResults->setSearchCriteria($searchCriteria);
     $searchResults->setItems($attributes);
     $searchResults->setTotalCount($totalCount);
     return $searchResults;
 }
Exemplo n.º 2
0
 /**
  * @param array $attributeCodes
  * @return mixed
  */
 protected function getAttributes($attributeCodes)
 {
     $attributeCollection = $this->attributeCollectionFactory->create();
     return $attributeCollection->addFieldToFilter('attribute_code', ['in' => $attributeCodes]);
 }