/** * {@inheritdoc} */ public function save(\Magento\Eav\Api\Data\AttributeGroupInterface $group) { try { $this->setRepository->get($group->getAttributeSetId()); } catch (NoSuchEntityException $ex) { throw NoSuchEntityException::singleField('attributeSetId', $group->getAttributeSetId()); } if ($group->getAttributeGroupId()) { /** @var \Magento\Eav\Model\Entity\Attribute\Group $existingGroup */ $existingGroup = $this->groupFactory->create(); $this->groupResource->load($existingGroup, $group->getAttributeGroupId()); if (!$existingGroup->getId()) { throw NoSuchEntityException::singleField('attributeGroupId', $existingGroup->getId()); } if ($existingGroup->getAttributeSetId() != $group->getAttributeSetId()) { throw new StateException(__('Attribute group does not belong to provided attribute set')); } } try { $this->groupResource->save($group); } catch (\Exception $e) { throw new StateException(__('Cannot save attributeGroup')); } return $group; }