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