Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
attribute_sets.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 $attributeSetFactory = $objectManager->get(\Magento\Eav\Api\Data\AttributeSetInterfaceFactory::class);
10 $dataObjectHelper = $objectManager->get(\Magento\Framework\Api\DataObjectHelper::class);
11 $attributeSetRepository = $objectManager->get(\Magento\Catalog\Api\AttributeSetRepositoryInterface::class);
12 $attributeSetManagement = $objectManager->get(\Magento\Eav\Api\AttributeSetManagementInterface::class);
13 
14 $entityTypeId = $objectManager->create(\Magento\Eav\Model\Entity\Type::class)->loadByCode('catalog_product')->getId();
15 $defaultAttributeSet = $objectManager->get(Magento\Eav\Model\Config::class)
16  ->getEntityType('catalog_product')
17  ->getDefaultAttributeSetId();
18 
20 $dataObjectHelper->populateWithArray(
22  [
23  'attribute_set_name' => 'Super Powerful Muffins',
24  'entity_type_id' => $entityTypeId,
25  ],
26  \Magento\Eav\Api\Data\AttributeSetInterface::class
27 );
28 $attributeSetManagement->create('catalog_product', $attributeSet, $defaultAttributeSet)->save();
29 
30 
32 $dataObjectHelper->populateWithArray(
34  [
35  'attribute_set_name' => 'Banana Rangers',
36  'entity_type_id' => $entityTypeId,
37  ],
38  \Magento\Eav\Api\Data\AttributeSetInterface::class
39 );
40 $attributeSetManagement->create('catalog_product', $attributeSet, $defaultAttributeSet)->save();
41 
43 $dataObjectHelper->populateWithArray(
45  [
46  'attribute_set_name' => 'Guardians of the Refrigerator',
47  'entity_type_id' => $entityTypeId,
48  ],
49  \Magento\Eav\Api\Data\AttributeSetInterface::class
50 );
51 $attributeSetManagement->create('catalog_product', $attributeSet, $defaultAttributeSet)->save();
$attributeSetManagement
$entityTypeId
$attributeSetRepository
$defaultAttributeSet
$objectManager
$attributeSetFactory
$dataObjectHelper
$attributeSet