![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-catalog/Model/Product/Attribute/ |
<?php /** * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Catalog\Model\Product\Attribute; use Magento\Framework\Exception\StateException; class SetManagement implements \Magento\Catalog\Api\AttributeSetManagementInterface { /** * @var \Magento\Eav\Api\AttributeSetManagementInterface */ protected $attributeSetManagement; /** * @var \Magento\Eav\Api\AttributeSetRepositoryInterface */ protected $attributeSetRepository; /** * @var \Magento\Eav\Model\Config */ protected $eavConfig; /** * @param \Magento\Eav\Api\AttributeSetManagementInterface $attributeSetManagement * @param \Magento\Eav\Api\AttributeSetRepositoryInterface $attributeSetRepository * @param \Magento\Eav\Model\Config $eavConfig */ public function __construct( \Magento\Eav\Api\AttributeSetManagementInterface $attributeSetManagement, \Magento\Eav\Api\AttributeSetRepositoryInterface $attributeSetRepository, \Magento\Eav\Model\Config $eavConfig ) { $this->attributeSetManagement = $attributeSetManagement; $this->attributeSetRepository = $attributeSetRepository; $this->eavConfig = $eavConfig; } /** * {@inheritdoc} */ public function create(\Magento\Eav\Api\Data\AttributeSetInterface $attributeSet, $skeletonId) { $this->validateSkeletonSet($skeletonId); return $this->attributeSetManagement->create( \Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE, $attributeSet, $skeletonId ); } /** * @param int $skeletonId * @return void * @throws StateException */ protected function validateSkeletonSet($skeletonId) { try { $skeletonSet = $this->attributeSetRepository->get($skeletonId); $productEntityId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId(); if ($skeletonSet->getEntityTypeId() != $productEntityId) { throw new StateException( __("The attribute set couldn't be created because it's based on a non-product attribute set.") ); } } catch (\Magento\Framework\Exception\NoSuchEntityException $exception) { throw new StateException( __("The attribute set couldn't be created because it's based on a non-existing attribute set.") ); } } }