Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
attribute_group_for_search.php
Go to the documentation of this file.
1 <?php
8 
12 $entityTypeId = $objectManager->create(\Magento\Eav\Model\Entity\Type::class)
13  ->loadByCode('catalog_product')
14  ->getId();
15 
17 $attributeSet = $objectManager->create(\Magento\Eav\Model\Entity\Attribute\Set::class);
18 $attributeSet->setData([
19  'attribute_set_name' => 'attribute_set_1_for_search',
20  'entity_type_id' => $entityTypeId,
21  'sort_order' => 100,
22 ]);
23 $attributeSet->validate();
24 $attributeSet->save();
25 
30  [
31  'attribute_set_id' => $attributeSet->getAttributeSetId(),
32  'sort_order' => 10,
33  'attribute_group_code' => 'attribute_group_1_for_search',
34  'default_id' => 1,
35  ],
36  [
37  'attribute_set_id' => $attributeSet->getAttributeSetId(),
38  'sort_order' => 20,
39  'attribute_group_code' => 'attribute_group_2_for_search',
40  'default_id' => 0,
41  ],
42  [
43  'attribute_set_id' => $attributeSet->getAttributeSetId(),
44  'sort_order' => 30,
45  'attribute_group_code' => 'attribute_group_3_for_search',
46  'default_id' => 0,
47  ],
48 ];
49 
50 foreach ($attributeGroupData as $data) {
52  $attributeGroup = $objectManager->create(\Magento\Eav\Model\Entity\Attribute\Group::class);
53  $attributeGroup->setData($data);
54  $attributeGroup->save();
55 }