Skip to main content

Magento 2.1.0 - category custom attribute


In the blog post, you can get how to create the category attributes to the database. In magento 2.0.0, it was enough to show the field on the category. But, in magento 2.1.0 onwards, we need to add some more code to show the field on the admin category edit page.

Create view/adminhtml/ui_component/category_form.xml and add the below code to add the custom field to the content section of the category. You can get all the list from vendor/magento/module-catalog/view/adminhtml/ui_component/category_form.xml.

<?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="content">
        <field name="sample_module_field">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">110</item>
                    <item name="dataType" xsi:type="string">string</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="label" xsi:type="string" translate="true">Custom Field</item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>




Comments

Popular posts from this blog

Magento 2 - Create a simple module

In magento 2, the creation of module has changed completely. We will go through how to create a module. Like earlier magento, we do not need to put our module files in different folders for code, theme, skin, etc. All, the codes related to the module should be inside one main folder. You can find the sample code in the git repo .

Magento 2 - Add to System Configuration

In magento 2, the system configuration has gone little changes. Now we can access the configuration from Stores > Settings > Configuration. Also, there is small changes in the system.xml file also. Now the system.xml file is inside etc/adminhtml/ folder. You can find the sample code in the git repo .