Created
July 12, 2016 04:08
-
-
Save techguysourav/a3766539447ba9d6705501971bb6411e to your computer and use it in GitHub Desktop.
Magento2 : Adding custom attributes to categories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Paarth\HelloWorld\Setup; | |
use Magento\Framework\Setup\UpgradeDataInterface; | |
use Magento\Framework\Setup\ModuleContextInterface; | |
use Magento\Framework\Setup\ModuleDataSetupInterface; | |
class UpgradeData implements UpgradeDataInterface | |
{ | |
protected $resourceConfig , $categorySetupFactory ; | |
public function __construct | |
(\Magento\Config\Model\ResourceModel\Config $resourceConfig, | |
\Magento\Catalog\Setup\CategorySetupFactory $categorySetupFactory | |
) { | |
$this->resourceConfig = $resourceConfig; | |
$this->categorySetupFactory = $categorySetupFactory; | |
} | |
public function upgrade(ModuleDataSetupInterface $setup, | |
ModuleContextInterface $context) { | |
if (version_compare($context->getVersion(), '2.0.4') < 0) { | |
$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]); | |
$entityTypeId = $categorySetup->getEntityTypeId | |
(\Magento\Catalog\Model\Category::ENTITY); | |
$categorySetup->addAttribute($entityTypeId, | |
'custom_text', array( | |
'type' => 'varchar', | |
'label' => 'HeloWorld label', | |
'input' => 'text', | |
'required' => false, | |
'group' => 'HelloWorld' | |
)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment