Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
select_attribute.php
Go to the documentation of this file.
1 <?php
7 
8 $objectManager = Bootstrap::getObjectManager();
9 
11 $installer = $objectManager->create(\Magento\Catalog\Setup\CategorySetup::class);
12 
14 $selectAttribute = $objectManager->create(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class);
15 $selectAttribute->setData(
16  [
17  'attribute_code' => 'select_attribute',
18  'entity_type_id' => $installer->getEntityTypeId('catalog_product'),
19  'is_global' => 1,
20  'is_user_defined' => 1,
21  'frontend_input' => 'select',
22  'is_unique' => 0,
23  'is_required' => 0,
24  'is_searchable' => 1,
25  'is_visible_in_advanced_search' => 0,
26  'is_comparable' => 0,
27  'is_filterable' => 1,
28  'is_filterable_in_search' => 0,
29  'is_used_for_promo_rules' => 0,
30  'is_html_allowed_on_front' => 1,
31  'is_visible_on_front' => 0,
32  'used_in_product_listing' => 0,
33  'used_for_sort_by' => 0,
34  'frontend_label' => ['Select Attribute'],
35  'backend_type' => 'varchar',
36  'backend_model' => \Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend::class,
37  'option' => [
38  'value' => [
39  'chair' => ['Chair'],
40  'table' => ['Table'],
41  ],
42  'order' => [
43  'chair' => 1,
44  'table' => 2,
45  ],
46  ],
47  ]
48 );
49 $selectAttribute->save();
50 
51 $installer->addAttributeToGroup(
52  'catalog_product',
53  'Default',
54  'General',
55  $selectAttribute->getId()
56 );
57 
60  \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection::class
61 );
62 $selectOptions->setAttributeFilter($selectAttribute->getId());
$installer
$selectOptionsIds
$selectOptions
$objectManager
$selectAttribute