Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
fixed_product_attribute.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
10 
12 $attributeSet = $objectManager->create(\Magento\Eav\Model\Entity\Attribute\Set::class);
13 
14 $entityType = $objectManager->create(\Magento\Eav\Model\Entity\Type::class)->loadByCode('catalog_product');
15 $defaultSetId = $objectManager->create(\Magento\Catalog\Model\Product::class)->getDefaultAttributeSetid();
16 
17 $attributeGroupId = $attributeSet->getDefaultGroupId($entityType->getDefaultAttributeSetId());
18 
20  'entity_type_id' => $entityType->getId(),
21  'attribute_code' => 'fixed_product_attribute',
22  'backend_model' => 'Magento\Weee\Model\Attribute\Backend\Weee\Tax',
23  'is_required' => 0,
24  'is_user_defined' => 1,
25  'is_static' => 1,
26  'attribute_set_id' => $defaultSetId,
27  'attribute_group_id' => $attributeGroupId,
28 ];
29 
31 $attribute = $objectManager->create(\Magento\Eav\Model\Entity\Attribute::class);
32 $attribute->setData($attributeData);
33 $attribute->save();