Site icon MageComp Blog

How to Add Comment Text for Product Attributes in Magento 2

how to add Helper Comment Text for Product Attributes in Magento 2

how to add Helper Comment Text for Product Attributes in Magento 2

Out of the box, Default Magento is come up with various functionality along with some helper text that makes that functionality easier to understand for the users. Generally, instead of spending the whole time in reading of user manual, these small things will help a user like a charm in need. As the name suggests, Helper text is designed to help the users and default Magento contains built in “attribute” class that let you to easily add comment or note beside the option for the better understanding for product users.

Code to add comment text for product attributes:

Here is Easiest way to add your own comment along with product attribute, all you need to add following code to InstallData.php file which is available at below path.
app\code\Vendor\Extension\Setup\InstallData.php

<!--?php namespace Vendorp\Extension\Setup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; class InstallData implements InstallDataInterface { private $eavSetupFactory; public function __construct(EavSetupFactory $eavSetupFactory) { $this->eavSetupFactory = $eavSetupFactory; } public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); $eavSetup->addAttribute( \Magento\Catalog\Model\Product::ENTITY, 'your_attribute_id', [ 'type' => 'text', 'label' => 'Attribute Label', 'input' => 'text', 'required' => false, 'sort_order' => 4, 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, 'group' => 'Attribute Groupe', 'note' => 'Attribute Comment' ] ); $setup->endSetup(); } } </pre> <p>You can now customize this code & comment according to your need and it will definitely work for you.<br ?-->
Hope this blog will help you to add comment text for product attributes. Try this and if you have any query then just comment below.
Happy Coding!
Exit mobile version