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 Attributes in Setup

Sometimes in our module we require to create product or category attributes automatically on module install. Also, we might require to add extra fields to quote, sales order, invoice, creditmemo tables. We will go through how to do that in magento 2. You can find the sample code in the git repo .