Created
July 12, 2016 04:11
-
-
Save techguysourav/335e1ce5224e030af1d50c6342d102a0 to your computer and use it in GitHub Desktop.
Magento2 :: Adding Custom Attributes To Products
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\Product::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