/**
  * {@inheritdoc}
  */
 public function getItems($entityType, $attributeCode)
 {
     if (empty($attributeCode)) {
         throw new InputException(__('Empty attribute code'));
     }
     $attribute = $this->attributeRepository->get($entityType, $attributeCode);
     try {
         $options = $attribute->getOptions();
     } catch (\Exception $e) {
         throw new StateException(__('Cannot load options for attribute %1', $attributeCode));
     }
     return $options;
 }
 /**
  * {@inheritdoc}
  */
 public function unassign($attributeSetId, $attributeCode)
 {
     try {
         $attributeSet = $this->setRepository->get($attributeSetId);
     } catch (NoSuchEntityException $e) {
         throw new NoSuchEntityException(__('Attribute set not found: %1', $attributeSetId));
     }
     $setEntityType = $this->entityTypeFactory->create()->getEntityType($attributeSet->getEntityTypeId());
     /** @var \Magento\Eav\Model\Entity\Attribute $attribute */
     $attribute = $this->attributeRepository->get($setEntityType->getEntityTypeCode(), $attributeCode);
     // Check if attribute is in set
     $attribute->setAttributeSetId($attributeSet->getAttributeSetId());
     $attribute->loadEntityAttributeIdBySet();
     if (!$attribute->getEntityAttributeId()) {
         throw new InputException(__('Attribute "%1" not found in attribute set %2.', $attributeCode, $attributeSetId));
     }
     if (!$attribute->getIsUserDefined()) {
         throw new StateException(__('System attribute can not be deleted'));
     }
     $attribute->deleteEntity();
     return true;
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
 {
     return $this->eavAttributeRepository->getList(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE, $searchCriteria);
 }