Here I need to Add defaul value of my custom category attribute in all existing category while I install the script.
here is my code:
<?php
namespace CommercePundit\HtmlSitemap\Setup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
class UpgradeData implements UpgradeDataInterface {
private $eavSetupFactory;
public function __construct(EavSetupFactory $eavSetupFactory) {
$this->eavSetupFactory = $eavSetupFactory;
}
public function upgrade( ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
if ( version_compare( $context->getVersion(), '1.0.1', '<' ) ) {
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(\Magento\Catalog\Model\Category::ENTITY, 'category_sitemap' , [
'type' => 'int',
'label' => 'Include in HTML Sitemap',
'input' => 'select',
'source' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class,
'default' => '1',
'sort_order' => 11,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'used_in_product_listing' => true,
'visible_on_front' => true,
'is_used_in_grid' => true,
'is_visible_in_grid' => true,
]);
}
}
}
And if it is wrong way that what I am doing then please suggest me the way of achieving this.