Reading list Switch to dark mode

    Add fields in Admin Category Form in Magento 2

    Updated 21 February 2024

    Today we are discussing how to add custom attributes/fields in category add/edit page in admin panel in  magento2.

    Firstly you have to create attribute for category.

    For example: you have created an attribute with attribute_code: “category_test_field”.

    Now, in magento 2.1.0 it does not displays the attributes by default in the form, to display attribute in category form you have to define it in ui_component.

    Now, create a file under app/code/Webkul/Test/view/adminhtml/ui_component/category_form.xml

    Searching for an experienced
    Magento 2 Company ?
    Find out More
    <?xml version="1.0" encoding="UTF-8"?>
    <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
        <fieldset name="general">
            <field name="category_test_field">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="sortOrder" xsi:type="number">50</item>
                        <item name="dataType" xsi:type="string">varchar</item>
                        <item name="formElement" xsi:type="string">input</item>
                        <item name="label" xsi:type="string" translate="true">Commission Test Field</item>
                        <item name="default" xsi:type="number">0</item>
                    </item>
                </argument>
            </field>
        </fieldset>
    </form>

    Here,

    category_from.xml : file name should be same, because we add a field in existing form. category_form is already defined in magento/catalog to display form.

    <fieldset name=’general’> : is the name of group in which you want to display your field.

    <field name=’category_test_field’> : is the attribute code to set/get the values of attribute.

    sortorder : is the number in which position you want your field in the form.

    datatype : is the type of data in which it stores the data.

    formelement : which type of form element you want to display for your attribute. for example: input, select, checkbox, etc.

    label : label of the attribute.

    default : default value to display.

    I hope this blog will help you with Add fields in Admin Category Form in Magento 2. You may also check our wide range of best Magento 2 Extensions.

    Please reach out to our team via a support ticket if you have any queries.

    Try this and if you have any queries then just comment below 🙂

    . . .

    Leave a Comment

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


    1 comments

  • Ragubathi U
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home