Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
attribute_set_with_renamed_group.php
Go to the documentation of this file.
1 <?php
9 use Magento\Eav\Api\Data\AttributeGroupInterfaceFactory;
11 use Magento\Eav\Api\Data\AttributeSetInterfaceFactory;
15 
16 $objectManager = Bootstrap::getObjectManager();
17 $attributeSetFactory = $objectManager->get(AttributeSetInterfaceFactory::class);
18 $attributeGroupFactory = $objectManager->get(AttributeGroupInterfaceFactory::class);
20 $dataObjectHelper = $objectManager->get(DataObjectHelper::class);
22 $attributeGroupRepository = $objectManager->get(AttributeGroupRepositoryInterface::class);
24 $attributeSetRepository = $objectManager->get(AttributeSetRepositoryInterface::class);
25 
28 $entityTypeId = $objectManager->create(Type::class)->loadByCode('catalog_product')->getId();
29 $dataObjectHelper->populateWithArray(
31  [
32  'attribute_set_name' => 'attribute_set_test',
33  'entity_type_id' => $entityTypeId,
34  ],
35  AttributeSetInterface::class
36 );
38 
41 $dataObjectHelper->populateWithArray(
43  [
44  'attribute_set_id' => $attributeSet->getAttributeSetId(),
45  'attribute_group_name' => 'attribute-group-name',
46  'default_id' => 1,
47  ],
48  AttributeGroupInterface::class
49 );
51 
52 // during renaming group code is not changed
53 $attributeGroup->setAttributeGroupName('attribute-group-renamed');