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
CatalogImportExport
Model
Import
_files
custom_attributes.php
Go to the documentation of this file.
1
<?php
7
$objectManager
=
\Magento\TestFramework\Helper\Bootstrap::getObjectManager
();
8
10
$entityType
=
$objectManager
->create(\
Magento
\Eav\Model\Entity\Type::class);
11
$entityType
->loadByCode(
'catalog_product'
);
12
$entityTypeId
=
$entityType
->getId();
13
15
$attributeSet
=
$objectManager
->create(\
Magento
\Eav\Model\Entity\Attribute\Set::class);
16
$attributeSet
->load(
'default'
,
'attribute_set_name'
);
17
$attributeSetId
=
$attributeSet
->getId();
18
19
$attributeGroupId
=
$attributeSet
->getDefaultGroupId(
$entityType
->getDefaultAttributeSetId());
20
21
$attributeData
= [
22
[
23
'attribute_code'
=>
'test_attribute'
,
24
'entity_type_id'
=>
$entityTypeId
,
25
'backend_type'
=>
'varchar'
,
26
'is_required'
=> 1,
27
'is_user_defined'
=> 1,
28
'is_unique'
=> 0,
29
'attribute_set_id'
=>
$attributeSetId
,
30
'attribute_group_id'
=>
$attributeGroupId
,
31
],
32
];
33
34
foreach
(
$attributeData
as
$data
) {
36
$attribute
=
$objectManager
->create(\
Magento
\Eav\Model\Entity\Attribute::class);
37
$attribute
->setData(
$data
);
38
$attribute
->setIsStatic(
true
);
39
$attribute
->save();
40
}
$attributeGroupId
$attributeGroupId
Definition:
custom_attributes.php:19
$entityType
$entityType
Definition:
custom_attributes.php:10
$attributeData
$attributeData
Definition:
custom_attributes.php:21
$attribute
$attribute
Definition:
attribute_set_with_image_attribute.php:41
$data
$data
Definition:
attribute_set_with_image_attribute.php:16
$attributeSet
$attributeSet
Definition:
custom_attributes.php:15
Magento
$entityTypeId
$entityTypeId
Definition:
custom_attributes.php:12
$attributeSetId
$attributeSetId
Definition:
custom_attributes.php:17
Magento\TestFramework\Helper\Bootstrap\getObjectManager
static getObjectManager()
Definition:
Bootstrap.php:125
$objectManager
$objectManager
Definition:
custom_attributes.php:7