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
dropdown_attribute.php
Go to the documentation of this file.
1
<?php
7
/* Create attribute */
9
$attribute
=
\Magento\TestFramework\Helper\Bootstrap::getObjectManager
()->create(
10
\
Magento
\Catalog\Model\
ResourceModel
\Eav\Attribute::class
11
);
12
13
if
(!
$attribute
->loadByCode(4,
'dropdown_attribute'
)->getId()) {
15
$installer
=
\Magento\TestFramework\Helper\Bootstrap::getObjectManager
()->create(
16
\
Magento
\Catalog\Setup\CategorySetup::class
17
);
18
19
$attribute
->setData(
20
[
21
'attribute_code'
=>
'dropdown_attribute'
,
22
'entity_type_id'
=>
$installer
->getEntityTypeId(
'catalog_product'
),
23
'is_global'
=> 0,
24
'is_user_defined'
=> 1,
25
'frontend_input'
=>
'select'
,
26
'is_unique'
=> 0,
27
'is_required'
=> 0,
28
'is_searchable'
=> 0,
29
'is_visible_in_advanced_search'
=> 0,
30
'is_comparable'
=> 0,
31
'is_filterable'
=> 0,
32
'is_filterable_in_search'
=> 0,
33
'is_used_for_promo_rules'
=> 0,
34
'is_html_allowed_on_front'
=> 1,
35
'is_visible_on_front'
=> 1,
36
'used_in_product_listing'
=> 1,
37
'used_for_sort_by'
=> 0,
38
'frontend_label'
=> [
'Drop-Down Attribute'
],
39
'backend_type'
=>
'varchar'
,
40
'backend_model'
=> \Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend::class,
41
'option'
=> [
42
'value'
=> [
43
'option_1'
=> [
'Option 1'
],
44
'option_2'
=> [
'Option 2'
],
45
'option_3'
=> [
'Option 3'
],
46
],
47
'order'
=> [
48
'option_1'
=> 1,
49
'option_2'
=> 2,
50
'option_3'
=> 3,
51
],
52
],
53
]
54
);
55
$attribute
->save();
56
57
/* Assign attribute to attribute set */
58
$installer
->addAttributeToGroup(
'catalog_product'
,
'Default'
,
'Attributes'
,
$attribute
->getId());
59
}
Magento\Catalog\Model\ResourceModel\Product
Definition:
CollectionTest.php:6
$installer
$installer
Definition:
configurable_attribute.php:16
Magento
$attribute
$attribute
Definition:
dropdown_attribute.php:9
Magento\TestFramework\Helper\Bootstrap\getObjectManager
static getObjectManager()
Definition:
Bootstrap.php:125