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
Elasticsearch
_files
multiselect_attribute.php
Go to the documentation of this file.
1
<?php
6
use
Magento\TestFramework\Helper\Bootstrap
;
7
8
$objectManager
= Bootstrap::getObjectManager();
9
11
$installer
= Bootstrap::getObjectManager()->create(\
Magento
\Catalog\Setup\CategorySetup::class);
12
14
$multiselectAttribute
=
$objectManager
->create(
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
61
$multiselectOptions
=
$objectManager
->create(
62
\
Magento
\Eav\Model\
ResourceModel
\Entity\Attribute\Option\Collection::class
63
);
64
$multiselectOptions
->setAttributeFilter(
$multiselectAttribute
->getId());
65
$multiselectOptionsIds
=
$multiselectOptions
->getAllIds();
$multiselectAttribute
$multiselectAttribute
Definition:
multiselect_attribute.php:14
$multiselectOptions
$multiselectOptions
Definition:
multiselect_attribute.php:61
Magento\Catalog\Model\ResourceModel\Product
Definition:
CollectionTest.php:6
Magento\TestFramework\Helper\Bootstrap
Definition:
Bootstrap.php:12
$multiselectOptionsIds
$multiselectOptionsIds
Definition:
multiselect_attribute.php:65
$objectManager
$objectManager
Definition:
multiselect_attribute.php:8
$installer
$installer
Definition:
multiselect_attribute.php:8
Magento