Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
magento2-base
dev
tests
integration
testsuite
Magento
Catalog
_files
multiselect_attribute.php
Go to the documentation of this file.
1
<?php
6
/* Create attribute */
8
$installer
=
\Magento\TestFramework\Helper\Bootstrap::getObjectManager
()->create(
9
\
Magento
\Catalog\Setup\CategorySetup::class
10
);
12
$attribute
=
\Magento\TestFramework\Helper\Bootstrap::getObjectManager
()->create(
13
\
Magento
\Catalog\Model\
ResourceModel
\Eav\Attribute::class
14
);
15
$entityType
=
$installer
->getEntityTypeId(
'catalog_product'
);
16
if
(!
$attribute
->loadByCode(
$entityType
,
'multiselect_attribute'
)->getAttributeId()) {
17
$attribute
->setData(
18
[
19
'attribute_code'
=>
'multiselect_attribute'
,
20
'entity_type_id'
=>
$entityType
,
21
'is_global'
=> 1,
22
'is_user_defined'
=> 1,
23
'frontend_input'
=>
'multiselect'
,
24
'is_unique'
=> 0,
25
'is_required'
=> 0,
26
'is_searchable'
=> 0,
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
'option_1'
=> [
'Option 1'
],
42
'option_2'
=> [
'Option 2'
],
43
'option_3'
=> [
'Option 3'
],
44
'option_4'
=> [
'Option 4 "!@#$%^&*'
]
45
],
46
'order'
=> [
47
'option_1'
=> 1,
48
'option_2'
=> 2,
49
'option_3'
=> 3,
50
'option_4'
=> 4,
51
],
52
],
53
]
54
);
55
$attribute
->save();
56
57
/* Assign attribute to attribute set */
58
$installer
->addAttributeToGroup(
'catalog_product'
,
'Default'
,
'General'
,
$attribute
->getId());
59
}
Magento\Catalog\Model\ResourceModel\Product
Definition:
CollectionTest.php:6
$entityType
$entityType
Definition:
multiselect_attribute.php:15
$installer
$installer
Definition:
multiselect_attribute.php:8
Magento
$attribute
$attribute
Definition:
multiselect_attribute.php:12
Magento\TestFramework\Helper\Bootstrap\getObjectManager
static getObjectManager()
Definition:
Bootstrap.php:125