1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
eavSetupFactory = $eavSetupFactory;
$this->categorySetupFactory = $categorySetupFactory;
}
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
Product::ENTITY,
'custom_attribute',
[
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'Custom Attribute',
'input' => 'text',
'class' => '',
'source' => '',
'global' => ScopedAttributeInterface::SCOPE_WEBSITE,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => '',
'searchable' => true,
'filterable' => true,
'comparable' => false,
'visible_on_front' => true,
'used_in_product_listing' => true,
'unique' => false,
]
);
$categoryId = $this->categorySetupFactory->create(['setup' => $setup]);
$categoryId->addAttributeToSet(
ProductAttributeInterface::ENTITY_TYPE_CODE,
Product::DEFAULT_ATTRIBUTE_SET_ID,
null,
'custom_attribute'
);
$setup->endSetup();
}
}
|