/**
  * {@inheritdoc}
  */
 public function getAttributes($entityType, $attributeSetId)
 {
     /** @var \Magento\Eav\Api\Data\AttributeSetInterface $attributeSet */
     $attributeSet = $this->setRepository->get($attributeSetId);
     $requiredEntityTypeId = $this->eavConfig->getEntityType($entityType)->getId();
     if (!$attributeSet->getAttributeSetId() || $attributeSet->getEntityTypeId() != $requiredEntityTypeId) {
         throw NoSuchEntityException::singleField('attributeSetId', $attributeSetId);
     }
     $attributeCollection = $this->attributeCollection->setAttributeSetFilter($attributeSet->getAttributeSetId())->load();
     return $attributeCollection->getItems();
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function getAttributeList($attributeSetId)
 {
     /** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */
     $attributeSet = $this->setFactory->create()->load($attributeSetId);
     $requiredEntityTypeId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId();
     if (!$attributeSet->getId() || $attributeSet->getEntityTypeId() != $requiredEntityTypeId) {
         // Attribute set does not exist
         throw NoSuchEntityException::singleField('attributeSetId', $attributeSetId);
     }
     $attributeCollection = $this->attributeCollection->setAttributeSetFilter($attributeSet->getId())->load();
     $attributes = array();
     /** @var \Magento\Eav\Model\Entity\Attribute $attribute */
     foreach ($attributeCollection as $attribute) {
         $attributes[] = $this->attributeBuilder->setId($attribute->getAttributeId())->setCode($attribute->getAttributeCode())->setFrontendLabel($attribute->getData('frontend_label'))->setDefaultValue($attribute->getDefaultValue())->setIsRequired((bool) $attribute->getData('is_required'))->setIsUserDefined((bool) $attribute->getData('is_user_defined'))->setFrontendInput($attribute->getData('frontend_input'))->create();
     }
     return $attributes;
 }