88 \
Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
108 $this->_attrGroupFactory = $attrGroupFactory;
109 $this->_attributeFactory = $attributeFactory;
110 $this->_resourceAttribute = $resourceAttribute;
132 $groups = $this->_attrGroupFactory->create()->getResourceCollection()->setAttributeSetFilter(
137 foreach ($groups as
$group) {
139 $newGroup->setId(
null)->setAttributeSetId($this->
getId())->setDefaultId($group->getDefaultId());
141 $groupAttributesCollection = $this->_attributeFactory
143 ->getResourceCollection()
144 ->setAttributeGroupFilter(
149 foreach ($groupAttributesCollection as
$attribute) {
150 $newAttribute = $this->_attributeFactory->create()
156 $newAttributes[] = $newAttribute;
158 $newGroup->setAttributes($newAttributes);
159 $newGroups[] = $newGroup;
161 $this->setGroups($newGroups);
177 $modelGroupArray = [];
178 $modelAttributeArray = [];
180 if (
$data[
'attributes']) {
185 $attributeIds = $this->_resourceAttribute->getValidAttributeIds($ids);
187 if (
$data[
'groups']) {
189 $modelGroup = $this->initGroupModel(
$group);
191 if (
$data[
'attributes']) {
194 $modelAttribute = $this->_attributeFactory->create();
195 $modelAttribute->setId(
197 )->setAttributeGroupId(
199 )->setAttributeSetId(
206 $modelAttributeArray[] = $modelAttribute;
209 $modelGroup->setAttributes($modelAttributeArray);
210 $modelAttributeArray = [];
212 $modelGroupArray[] = $modelGroup;
214 $this->setGroups($modelGroupArray);
217 if (
$data[
'not_attributes']) {
218 $modelAttributeArray = [];
219 $data[
'not_attributes'] = array_filter(
$data[
'not_attributes']);
220 foreach (
$data[
'not_attributes'] as $entityAttributeId) {
221 $entityAttribute = $this->_resourceAttribute->getEntityAttribute($entityAttributeId);
222 if (!$entityAttribute) {
225 'The entity attribute with the "%1" ID isn\'t found. Reset the attribute and try again.',
230 $modelAttribute = $this->_eavConfig->getAttribute(
232 $entityAttribute[
'attribute_id']
234 $modelAttribute->setEntityAttributeId($entityAttributeId);
235 $modelAttributeArray[] = $modelAttribute;
237 $this->setRemoveAttributes($modelAttributeArray);
240 if (
$data[
'removeGroups']) {
241 $modelGroupArray = [];
243 $modelGroup = $this->_attrGroupFactory->create();
246 $modelGroupArray[] = $modelGroup;
248 $this->setRemoveGroups($modelGroupArray);
259 private function initGroupModel(
$group)
261 $modelGroup = $this->_attrGroupFactory->create();
264 )->setAttributeGroupName(
266 )->setAttributeSetId(
271 if ($modelGroup->getId()) {
272 $group = $this->_attrGroupFactory->create()->load($modelGroup->getId());
274 $modelGroup->setAttributeGroupCode(
$group->getAttributeGroupCode());
289 if ($attributeSetName ==
'') {
290 throw new LocalizedException(
__(
'The attribute set name is empty. Enter the name and try again.'));
295 __(
'A "%1" attribute set name already exists. Create a new name and try again.', $attributeSetName)
317 if ($setId && is_array(
$attribute->getAttributeSetInfo($setId))) {
323 $attributeIds[] =
$attribute->getAttributeId();
327 $setInfo = $this->
_getResource()->getSetInfo($attributeIds, $setId);
334 if (!in_array(
$attribute->getAttributeId(), $attributeIds)) {
337 if (is_numeric($setId)) {
338 $attributeSetInfo =
$attribute->getAttributeSetInfo();
339 if (!is_array($attributeSetInfo)) {
340 $attributeSetInfo = [];
342 if (isset($setInfo[
$attribute->getAttributeId()][$setId])) {
343 $attributeSetInfo[$setId] = $setInfo[
$attribute->getAttributeId()][$setId];
345 $attribute->setAttributeSetInfo($attributeSetInfo);
347 if (isset($setInfo[
$attribute->getAttributeId()])) {
367 if ($setId ===
null) {
368 $setId = $this->
getId();
371 return $setId ? $this->
_getResource()->getDefaultGroupId($setId) :
null;
382 return $this->_resource ?: parent::_getResource();
391 return $this->
getData(self::KEY_ATTRIBUTE_SET_ID);
399 return $this->
getData(self::KEY_ATTRIBUTE_SET_NAME);
407 return $this->
getData(self::KEY_SORT_ORDER);
415 return $this->
getData(self::KEY_ENTITY_TYPE_ID);
448 return $this->
setData(self::KEY_ATTRIBUTE_SET_NAME, $attributeSetName);
459 return $this->
setData(self::KEY_SORT_ORDER, $sortOrder);
getDefaultGroupId($setId=null)
const KEY_ATTRIBUTE_SET_ID
_getExtensionAttributes()
initFromSkeleton($skeletonId)
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
load($modelId, $field=null)
addSetInfo($entityType, array $attributes, $setId=null)
setAttributeSetName($attributeSetName)
const KEY_ATTRIBUTE_SET_NAME
setEntityTypeId($entityTypeId)
getData($key='', $index=null)
setExtensionAttributes(\Magento\Eav\Api\Data\AttributeSetExtensionInterface $extensionAttributes)
setData($key, $value=null)
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Eav\Model\Config $eavConfig, \Magento\Eav\Model\Entity\Attribute\GroupFactory $attrGroupFactory, \Magento\Eav\Model\Entity\AttributeFactory $attributeFactory, \Magento\Eav\Model\ResourceModel\Entity\Attribute $resourceAttribute, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
setAttributeSetId($attributeSetId)
if(!isset($_GET['name'])) $name