Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
search_attributes.php
Go to the documentation of this file.
1 <?php
7 /* Create attribute */
10  \Magento\Catalog\Setup\CategorySetup::class
11 );
12 
14  [
15  'attribute_code' => 'test_quick_search',
16  'is_filterable_in_search' => 1,
17  ],
18  [
19  'attribute_code' => 'test_catalog_view',
20  'is_filterable' => 1,
21  ]
22 ];
23 
24 foreach ($attributesData as $data) {
25 
28  \Magento\Catalog\Model\ResourceModel\Eav\Attribute::class
29  );
30  $attributeData = array_merge(
31  [
32  'attribute_code' => '',
33  'entity_type_id' => $installer->getEntityTypeId('catalog_product'),
34  'is_global' => 1,
35  'is_user_defined' => 1,
36  'frontend_input' => 'select',
37  'is_unique' => 0,
38  'is_required' => 1,
39  'is_searchable' => 0,
40  'is_visible_in_advanced_search' => 0,
41  'is_comparable' => 0,
42  'is_filterable' => 0,
43  'is_filterable_in_search' => 0,
44  'is_used_for_promo_rules' => 0,
45  'is_html_allowed_on_front' => 1,
46  'is_visible_on_front' => 0,
47  'used_in_product_listing' => 0,
48  'used_for_sort_by' => 0,
49  'frontend_label' => ['Test Configurable'],
50  'backend_type' => 'int',
51  'option' => [
52  'value' => ['option_0' => ['Option 1'], 'option_1' => ['Option 2']],
53  'order' => ['option_0' => 1, 'option_1' => 2],
54  ],
55  ],
56  $data
57  );
58  $attribute->setData($attributeData);
59  $attribute->save();
60  /* Assign attribute to attribute set */
61  $installer->addAttributeToGroup('catalog_product', 'Default', 'General', $attribute->getId());
62 }
63 
66 $eavConfig->clear();
$installer
$attributesData