I have created install script to add an attribute to category.
Default value has to be set, thus 'default' => '1', is used.
InstallData.php file:
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
Category::ENTITY,
'my_attr',
[
'type' => 'int',
'label' => 'My',
'input' => 'select',
'default' => '1',
'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
'required' => false,
'sort_order' => 100,
'group' => 'General',
]
);
}
The problem is that later when I use $cat->getMyAttr() I can get this only when I have set it to true or false in admin panel and saved settings. Otherwise I get just null.
In other words default value is not being set during setup of the module. How to set default value that will be set to all the categories with setup script?