• en
  • hy

Magento 2 – How to add new category attribute

Hi. In this Magento 2 tutorial, we are going to create a new category attribute and show it on backend category edit pages. We will use text input type, but the similar approach can be used for creating Dropdowns, Radio, etc. We will create a new module (you can add this functionality to existing module as well). Creating a basic module is out of scope of this tutorial.

Next we need to create a setup script for our module. Setup scripts in Magento 2 should be created in Yereone/NewCategoryAttribute/Setup/InstallData.php. The content will be the following

Now we have the new attribute on category entity type. But if we want it to be editable on backend, we need to add it to the backend form.
The category backend form is rendered by category_form.xml UI component. The next step is to create a new xml file in
Yereone/NewCategoryAttribute/view/adminhtml/ui_component/category_form.xml with the following content

Now you should already see the value in admin form. If you want the input type of the attribute to select box, you should specify it on the xml like this

Where “options” is the source model of the select box.
Magento 2 How to add new category attribute and show in grid

Here is the module with all files in Yereone Github Repository.
If you want to add new order attribute, check out our other tutorial from Magento 2 series

We are Magento Development Company. Contact US now.!

Please Vote Here
[Total: 1 Average: 5]

Leave a Reply

Your email address will not be published. Required fields are marked *

Still can’t add the category attribute?. Contact US now.!