/** * Get applicable attributes * * @param array $documentIds * @return array */ private function getApplicableAttributeCodes(array $documentIds) { $attributeSetIds = $this->attributeSetFinder->findAttributeSetIdsByProductIds($documentIds); $searchCriteria = $this->searchCriteriaBuilder->addFilter('attribute_set_id', $attributeSetIds, 'in')->create(); $result = $this->productAttributeRepository->getList($searchCriteria); $attributeCodes = []; foreach ($result->getItems() as $attribute) { $attributeCodes[] = $attribute->getAttributeCode(); } return $attributeCodes; }
/** * Get array of attributes information * * Array contains attribute label and options labels * * @return array */ private function getAttributes() { $attributes = []; foreach ($this->attributeRepository->getList($this->getSearchCriteria())->getItems() as $attribute) { $attributeCode = $attribute->getAttributeCode(); $attributes[$attributeCode] = ['label' => $attribute->getDefaultFrontendLabel()]; $options = $attribute->getOptions(); if (is_array($options)) { foreach ($options as $option) { $attributes[$attributeCode]['options'][$option->getValue()] = $option->getLabel(); } } } return $attributes; }
/** * {@inheritdoc} */ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) { /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */ $collection = $this->collectionFactory->create(); $this->extensionAttributesJoinProcessor->process($collection); foreach ($this->metadataService->getList($this->searchCriteriaBuilder->create())->getItems() as $metadata) { $collection->addAttributeToSelect($metadata->getAttributeCode()); } $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner'); $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner'); //Add filters from root filter group to the collection foreach ($searchCriteria->getFilterGroups() as $group) { $this->addFilterGroupToCollection($group, $collection); } /** @var SortOrder $sortOrder */ foreach ((array) $searchCriteria->getSortOrders() as $sortOrder) { $field = $sortOrder->getField(); $collection->addOrder($field, $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC'); } $collection->setCurPage($searchCriteria->getCurrentPage()); $collection->setPageSize($searchCriteria->getPageSize()); $collection->load(); $searchResult = $this->searchResultsFactory->create(); $searchResult->setSearchCriteria($searchCriteria); $searchResult->setItems($collection->getItems()); $searchResult->setTotalCount($collection->getSize()); return $searchResult; }
/** * {@inheritdoc} */ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) { /** @var \Magento\Catalog\Model\Resource\Product\Collection $collection */ $collection = $this->collectionFactory->create(); $defaultAttributeSetId = $this->eavConfig->getEntityType(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE)->getDefaultAttributeSetId(); $extendedSearchCriteria = $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField('attribute_set_id')->setValue($defaultAttributeSetId)->create()]); foreach ($this->metadataService->getList($extendedSearchCriteria->create())->getItems() as $metadata) { $collection->addAttributeToSelect($metadata->getAttributeCode()); } $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner'); $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner'); //Add filters from root filter group to the collection foreach ($searchCriteria->getFilterGroups() as $group) { $this->addFilterGroupToCollection($group, $collection); } /** @var SortOrder $sortOrder */ foreach ((array) $searchCriteria->getSortOrders() as $sortOrder) { $field = $sortOrder->getField(); $collection->addOrder($field, $sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC ? 'ASC' : 'DESC'); } $collection->setCurPage($searchCriteria->getCurrentPage()); $collection->setPageSize($searchCriteria->getPageSize()); $collection->load(); $searchResult = $this->searchResultsFactory->create(); $searchResult->setSearchCriteria($searchCriteria); $searchResult->setItems($collection->getItems()); $searchResult->setTotalCount($collection->getSize()); return $searchResult; }
/** * Get attribute codes of prev set * * @return array * @throws \Magento\Framework\Exception\LocalizedException */ private function getPreviousSetAttributes() { if ($this->prevSetAttributes === null) { $searchCriteria = $this->searchCriteriaBuilder->addFilter('attribute_set_id', $this->getPreviousSetId())->create(); $attributes = $this->attributeRepository->getList($searchCriteria)->getItems(); $this->prevSetAttributes = []; foreach ($attributes as $attribute) { $this->prevSetAttributes[] = $attribute->getAttributeCode(); } } return $this->prevSetAttributes; }
/** * @return array * @throws \Magento\Framework\Exception\LocalizedException */ private function getAttributeTables() { $searchResult = $this->productAttributeRepository->getList($this->searchCriteriaBuilder->create()); $attributeTables = []; /** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $productAttribute */ foreach ($searchResult->getItems() as $productAttribute) { $attributeTable = $productAttribute->getBackend()->getTable(); if (!in_array($attributeTable, $attributeTables) && $attributeTable != $this->attributeResource->getTable('catalog_product_entity')) { $attributeTables[] = $attributeTable; } } return $attributeTables; }
/** * Returns attributes * * @return \Magento\Catalog\Api\Data\ProductAttributeInterface[] */ protected function getAttributes() { return $this->productAttributeRepository->getList($this->searchCriteria)->getItems(); }