Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SetManagement.php
Go to the documentation of this file.
1 <?php
9 
11 
13 {
18 
23 
27  protected $eavConfig;
28 
34  public function __construct(
35  \Magento\Eav\Api\AttributeSetManagementInterface $attributeSetManagement,
36  \Magento\Eav\Api\AttributeSetRepositoryInterface $attributeSetRepository,
37  \Magento\Eav\Model\Config $eavConfig
38  ) {
39  $this->attributeSetManagement = $attributeSetManagement;
40  $this->attributeSetRepository = $attributeSetRepository;
41  $this->eavConfig = $eavConfig;
42  }
43 
47  public function create(\Magento\Eav\Api\Data\AttributeSetInterface $attributeSet, $skeletonId)
48  {
49  $this->validateSkeletonSet($skeletonId);
50  return $this->attributeSetManagement->create(
51  \Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE,
53  $skeletonId
54  );
55  }
56 
62  protected function validateSkeletonSet($skeletonId)
63  {
64  try {
65  $skeletonSet = $this->attributeSetRepository->get($skeletonId);
66  $productEntityId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId();
67  if ($skeletonSet->getEntityTypeId() != $productEntityId) {
68  throw new StateException(
69  __("The attribute set couldn't be created because it's based on a non-product attribute set.")
70  );
71  }
72  } catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
73  throw new StateException(
74  __("The attribute set couldn't be created because it's based on a non-existing attribute set.")
75  );
76  }
77  }
78 }
__()
Definition: __.php:13
__construct(\Magento\Eav\Api\AttributeSetManagementInterface $attributeSetManagement, \Magento\Eav\Api\AttributeSetRepositoryInterface $attributeSetRepository, \Magento\Eav\Model\Config $eavConfig)
create(\Magento\Eav\Api\Data\AttributeSetInterface $attributeSet, $skeletonId)