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
product_simple_with_custom_attribute.php
Go to the documentation of this file.
1
<?php
7
include
__DIR__
.
'/product_simple_with_full_option_set.php'
;
8
10
$objectManager
=
\Magento\TestFramework\Helper\Bootstrap::getObjectManager
();
11
13
$productRepository
=
$objectManager
->create(\
Magento
\Catalog\Api\ProductRepositoryInterface::class);
14
16
$installer
=
$objectManager
->create(\
Magento
\Catalog\Setup\CategorySetup::class);
17
$entityModel
=
$objectManager
->create(\
Magento
\Eav\Model\Entity::class);
18
$attributeSetId
=
$installer
->getAttributeSetId(
'catalog_product'
,
'Default'
);
19
$entityTypeId
=
$entityModel
->setType(\
Magento
\Catalog\Model\Product::ENTITY)->getTypeId();
20
$groupId
=
$installer
->getDefaultAttributeGroupId(
$entityTypeId
,
$attributeSetId
);
21
23
$attribute
=
$objectManager
->create(\
Magento
\Catalog\Model\
ResourceModel
\Eav\Attribute::class);
24
$attribute
->setAttributeCode(
25
'attribute_code_custom'
26
)->setEntityTypeId(
27
$entityTypeId
28
)->setIsVisible(
true
)->setFrontendInput(
29
'text'
30
)->setFrontendLabel(
31
'custom_attributes_frontend_label'
32
)->setAttributeGroupId(
33
$groupId
34
)->setIsFilterable(
35
1
36
)->setIsUserDefined(
37
1
38
)->setBackendType(
39
$attribute
->getBackendTypeByInput(
$attribute
->getFrontendInput())
40
)->save();
41
42
$product
=
$productRepository
->get(
'simple'
,
true
);
43
44
$product
->setCustomAttribute(
$attribute
->getAttributeCode(),
'customAttributeValue'
);
45
46
$productRepository
->save(
$product
);
Magento\Catalog\Model\ResourceModel\Product
Definition:
CollectionTest.php:6
$attributeSetId
$attributeSetId
Definition:
product_simple_with_custom_attribute.php:18
$objectManager
$objectManager
Definition:
product_simple_with_custom_attribute.php:10
__DIR__
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition:
_bootstrap.php:60
$product
$product
Definition:
product_simple_with_custom_attribute.php:42
$installer
$installer
Definition:
product_simple_with_custom_attribute.php:16
Magento
$entityModel
$entityModel
Definition:
product_simple_with_custom_attribute.php:17
$entityTypeId
$entityTypeId
Definition:
product_simple_with_custom_attribute.php:19
$groupId
$groupId
Definition:
product_simple_with_custom_attribute.php:20
$attribute
$attribute
Definition:
product_simple_with_custom_attribute.php:23
$productRepository
$productRepository
Definition:
product_simple_with_custom_attribute.php:13
Magento\TestFramework\Helper\Bootstrap\getObjectManager
static getObjectManager()
Definition:
Bootstrap.php:125