Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductAttributeGroupRepository.php
Go to the documentation of this file.
1 <?php
8 namespace Magento\Catalog\Model;
9 
12 
14 {
18  protected $groupRepository;
19 
23  protected $groupFactory;
24 
28  protected $groupResource;
29 
35  public function __construct(
36  \Magento\Eav\Api\AttributeGroupRepositoryInterface $groupRepository,
37  \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group $groupResource,
38  \Magento\Catalog\Model\Product\Attribute\GroupFactory $groupFactory
39  ) {
40  $this->groupRepository = $groupRepository;
41  $this->groupResource = $groupResource;
42  $this->groupFactory = $groupFactory;
43  }
44 
48  public function save(\Magento\Eav\Api\Data\AttributeGroupInterface $group)
49  {
50  return $this->groupRepository->save($group);
51  }
52 
56  public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
57  {
58  return $this->groupRepository->getList($searchCriteria);
59  }
60 
64  public function get($groupId)
65  {
67  $group = $this->groupFactory->create();
68  $this->groupResource->load($group, $groupId);
69  if (!$group->getId()) {
70  throw new NoSuchEntityException(
71  __('The group with the "%1" ID doesn\'t exist. Verify the ID and try again.', $groupId)
72  );
73  }
74  return $group;
75  }
76 
80  public function deleteById($groupId)
81  {
82  $this->delete(
83  $this->get($groupId)
84  );
85  return true;
86  }
87 
92  {
94  if ($group->hasSystemAttributes()) {
95  throw new StateException(
96  __("The attribute group can't be deleted because it contains system attributes.")
97  );
98  }
99  return $this->groupRepository->delete($group);
100  }
101 }
$group
Definition: sections.phtml:16
__()
Definition: __.php:13
$searchCriteria
__construct(\Magento\Eav\Api\AttributeGroupRepositoryInterface $groupRepository, \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group $groupResource, \Magento\Catalog\Model\Product\Attribute\GroupFactory $groupFactory)
getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
save(\Magento\Eav\Api\Data\AttributeGroupInterface $group)