{"id":609,"date":"2019-09-24T12:13:22","date_gmt":"2019-09-24T12:13:22","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/09\/24\/add-category-attribute-to-custom-attribute-group-in-magento-2\/"},"modified":"2025-05-22T15:56:21","modified_gmt":"2025-05-22T10:26:21","slug":"add-category-attribute-to-custom-attribute-group-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/add-category-attribute-to-custom-attribute-group-in-magento-2\/","title":{"rendered":"How to Add Category Attribute to Custom Attribute Group in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Attributes in Magento 2 are of great help! However, not all the time the default attributes are enough when it comes to satisfying the business requirements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, you may have created a custom group in Magento 2 admin panel where you want to create a category attribute. For that, you need to implement the below method.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you are developing a module and need to customize the native feature or add a new feature altogether, adding a custom group is a must. For example, integrating a third-party API and using a category attribute!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And, you may find this method to <em><strong>add category attribute to custom attribute group in Magento 2<\/strong><\/em> helpful for the same.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Add Category Attribute to Custom Attribute Group in Magento 2:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create your category attribute using <strong>InstallData.php<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace [Vendor]\\[Module]\\Setup;\n\nuse Magento\\Eav\\Setup\\EavSetupFactory;\nuse Magento\\Framework\\Setup\\InstallDataInterface;\nuse Magento\\Framework\\Setup\\ModuleContextInterface;\nuse Magento\\Framework\\Setup\\ModuleDataSetupInterface;\nuse Magento\\Eav\\Model\\Entity\\Attribute\\ScopedAttributeInterface;\nuse Magento\\Catalog\\Model\\Category;\n\nclass InstallData implements InstallDataInterface\n{\n    private $eavSetupFactory;\n    \n    public function __construct(EavSetupFactory $eavSetupFactory)\n    {\n        $this->eavSetupFactory = $eavSetupFactory;\n    }\n    \n    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)\n    {\n        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);\n\n        $eavSetup->addAttribute(\n            Category::ENTITY,\n            'custom_category_attribute',\n            [\n                'group' => 'Custom Category Group',\n                'type' => 'text',\n                'label' => 'Category Attribute',\n                'input' => 'text',\n                'required' => false,\n                'sort_order' => 100,\n                'global' => ScopedAttributeInterface::SCOPE_STORE,\n                'visible' => true,\n                'user_defined' => true,\n                'backend' => ''\n            ]\n        );\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create <strong>category_form.xml<\/strong> file at <\/p>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\"><strong><strong>[<strong><strong>Vendor]\\[Module]\\view\\adminhtml\\ui_component\\category_form.xml<\/strong><\/strong><\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?>\n&lt;form xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n      xsi:noNamespaceSchemaLocation=\"urn:magento:module:Magento_Ui:etc\/ui_configuration.xsd\">\n    &lt;fieldset name=\"custom_category_group\">\n        &lt;argument name=\"data\" xsi:type=\"array\">\n            &lt;item name=\"config\" xsi:type=\"array\">\n                &lt;item name=\"label\" xsi:type=\"string\">Custom Category Group&lt;\/item> &lt;!-- your category group name -->\n                &lt;item name=\"collapsible\" xsi:type=\"boolean\">true&lt;\/item>\n                &lt;item name=\"sortOrder\" xsi:type=\"number\">99&lt;\/item>\n            &lt;\/item>\n        &lt;\/argument>\n        &lt;field name=\"custom_category_attribute\"> &lt;!-- your attribute code -->\n            &lt;argument name=\"data\" xsi:type=\"array\">\n                &lt;item name=\"config\" xsi:type=\"array\">\n                    &lt;item name=\"sortOrder\" xsi:type=\"number\">100&lt;\/item>\n                    &lt;item name=\"dataType\" xsi:type=\"string\">string&lt;\/item>\n                    &lt;item name=\"label\" xsi:type=\"string\" translate=\"true\">Category Attribute Name&lt;\/item>\n                    &lt;item name=\"formElement\" xsi:type=\"string\">input&lt;\/item>\n                    &lt;item name=\"notice\" xsi:type=\"string\">add comment&lt;\/item>\n                &lt;\/item>\n            &lt;\/argument>\n        &lt;\/field>\n    &lt;\/fieldset>\n&lt;\/form><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also <a href=\"https:\/\/meetanshi.com\/blog\/create-custom-order-attribute-in-magento-2-and-show-it-in-admin-grid\/\">create custom order attribute<\/a> in Magento 2 which will be seen in admin grid which will help your business to manage and fulfill online orders efficiently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, do share the solution with the Magento community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Attributes in Magento 2 are of great help! However, not all the time the default attributes are enough when it comes to satisfying the business&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-609","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/609","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=609"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/609\/revisions"}],"predecessor-version":[{"id":15261,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/609\/revisions\/15261"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=609"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}