Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
multiselect_attribute_with_incorrect_values.php
Go to the documentation of this file.
1 <?php
7 /* Create attribute */
10  \Magento\Catalog\Setup\CategorySetup::class
11 );
14  \Magento\Catalog\Model\ResourceModel\Eav\Attribute::class
15 );
16 $attribute->setData(
17  [
18  'attribute_code' => 'multiselect_attribute',
19  'entity_type_id' => $installer->getEntityTypeId('catalog_product'),
20  'is_global' => 1,
21  'is_user_defined' => 1,
22  'frontend_input' => 'multiselect',
23  'is_unique' => 0,
24  'is_required' => 0,
25  'is_searchable' => 0,
26  'is_visible_in_advanced_search' => 0,
27  'is_comparable' => 0,
28  'is_filterable' => 0,
29  'is_filterable_in_search' => 0,
30  'is_used_for_promo_rules' => 0,
31  'is_html_allowed_on_front' => 1,
32  'is_visible_on_front' => 0,
33  'used_in_product_listing' => 0,
34  'used_for_sort_by' => 0,
35  'frontend_label' => ['Multiselect Attribute'],
36  'backend_type' => 'varchar',
37  'backend_model' => \Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend::class,
38  'option' => [
39  'value' => [
40  'option_1' => ['Opt|,=ion 1'],
41  'option_2' => ['Opt||,ion 2'],
42  'option_3' => ['Option 3 "!@#$%^&*, "|"']
43  ],
44  'order' => [
45  'option_1' => 1,
46  'option_2' => 2,
47  'option_3' => 3,
48  ],
49  ],
50  ]
51 );
52 $attribute->save();
53 
54 /* Assign attribute to attribute set */
55 $installer->addAttributeToGroup('catalog_product', 'Default', 'General', $attribute->getId());