/** * {@inheritdoc} */ public function delete(\Magento\Eav\Api\Data\AttributeGroupInterface $group) { /** @var \Magento\Catalog\Model\Product\Attribute\Group $group */ if ($group->hasSystemAttributes()) { throw new StateException(__('Attribute group that contains system attributes can not be deleted')); } return $this->groupRepository->delete($group); }
/** * {@inheritdoc} */ public function assign($entityTypeCode, $attributeSetId, $attributeGroupId, $attributeCode, $sortOrder) { try { $attributeSet = $this->setRepository->get($attributeSetId); } catch (NoSuchEntityException $ex) { throw new NoSuchEntityException(__('AttributeSet with id "%1" does not exist.', $attributeSetId)); } $setEntityType = $this->entityTypeFactory->create()->getEntityType($attributeSet->getEntityTypeId()); if ($setEntityType->getEntityTypeCode() != $entityTypeCode) { throw new InputException(__('Wrong attribute set id provided')); } //Check if group exists. If not - expected exception $attributeGroup = $this->groupRepository->get($attributeGroupId); if ($attributeGroup->getAttributeSetId() != $attributeSetId) { throw new InputException(__('Attribute group does not belong to attribute set')); } /** @var \Magento\Eav\Api\Data\AttributeInterface $attribute */ $attribute = $this->attributeRepository->get($entityTypeCode, $attributeCode); $this->attributeResource->saveInSetIncluding($attribute, $attribute->getAttributeId(), $attributeSetId, $attributeGroupId, $sortOrder); $attribute->setAttributeSetId($attributeSetId); return $attribute->loadEntityAttributeIdBySet()->getData('entity_attribute_id'); }