/**
  * {@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);
 }
Ejemplo n.º 2
0
 /**
  * {@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;
 }
Ejemplo n.º 3
0
 /**
  * Calculate group code based on group name.
  *
  * TODO: This logic is copy-pasted from \Magento\Eav\Model\Entity\Attribute\Group::beforeSave
  * TODO: and should be moved to a separate service, which will allow two-way conversion groupName <=> groupCode
  * TODO: Remove after MAGETWO-48290 is complete
  *
  * @param AttributeGroupInterface $group
  * @return string
  */
 private function calculateGroupCode(AttributeGroupInterface $group)
 {
     $attributeGroupCode = $group->getAttributeGroupCode();
     if ($attributeGroupCode === 'images') {
         $attributeGroupCode = 'image-management';
     }
     return $attributeGroupCode;
 }
Ejemplo n.º 4
0
 /**
  * Calculate group code based on group name.
  *
  * TODO: This logic is copy-pasted from \Magento\Eav\Model\Entity\Attribute\Group::beforeSave
  * TODO: and should be moved to a separate service, which will allow two-way conversion groupName <=> groupCode
  * TODO: Remove after MAGETWO-48290 is complete
  *
  * @param AttributeGroupInterface $group
  * @return string
  */
 private function calculateGroupCode(AttributeGroupInterface $group)
 {
     $groupName = $group->getAttributeGroupName();
     $attributeGroupCode = trim(preg_replace('/[^a-z0-9]+/', '-', $this->translitFilter->filter(strtolower($groupName))), '-');
     if ($attributeGroupCode == 'images') {
         $attributeGroupCode = 'image-management';
     }
     if (empty($attributeGroupCode)) {
         // in the following code md5 is not used for security purposes
         $attributeGroupCode = md5($groupName);
     }
     return $attributeGroupCode;
 }