Closed
Description
I need to add custom attributes for category. I have added couple of custom attributes for category using the install script. Now i need to add another couple of attributes. I have tried with the following code but it didn't worked
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */
$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
$entityTypeId = $categorySetup->getEntityTypeId(\Magento\Catalog\Model\Category::ENTITY);
$attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId);
$testAttributeGroupId = $categorySetup->getAttributeGroupId($entityTypeId, $attributeSetId, 'Test');
$categorySetup->addAttribute(
\Magento\Catalog\Model\Category::ENTITY, 'custom_link', [
'type' => 'text',
'label' => 'Custom Link',
'input' => 'text',
'required' => false,
'sort_order' => 30,
'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_STORE,
'is_html_allowed_on_front' => true,
'group' => 'Test',
'default' => ''
]
);
$categorySetup->addAttribute(
\Magento\Catalog\Model\Category::ENTITY, 'display_shop_all', [
'type' => 'int',
'label' => 'Display Shop All',
'input' => 'select',
'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
'required' => false,
'sort_order' => 40,
'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_STORE,
'group' => 'Test',
]
);
$categorySetup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$testAttributeGroupId,
'custom_link',
30
);
$categorySetup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$testAttributeGroupId,
'display_shop_all',
40
);
}
Metadata
Metadata
Assignees
Labels
No labels