5

I follow this link to add a new tab in config. Is there a way to add a custom config section in an existing tab for Magento 2?

14

Yes, we can do this.

We should take a look:

vendor/magento/module-payment/etc/adminhtml/system.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <section id="payment" translate="label" type="text" sortOrder="400" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Payment Methods</label>
            <tab>sales</tab>
            <resource>Magento_Payment::payment</resource>
        </section>
    </system>
</config>

The sales tab was defined from vendor/magento/module-sales/etc/adminhtml/system.xml. So, when we want to create a new section under SALES tab, we create a new section with <tab>sales</tab> node.

app/code/Vendor1/Module1/etc/adminhtml/system.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <section id="custom_tab1" translate="label" type="text" sortOrder="401" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Your custom tab 1</label>
            <tab>sales</tab>
            <resource>Vendor_Module::custom</resource>
        </section>
    </system>
</config>

Or if we want to add a custom field to an existing section - custom_tab1. Declare our custom fields inside this section.

app/code/Vendor2/Module2/etc/adminhtml/system.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
    <section id="custom_tab1">
        <group id="custom_group1" translate="label" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="0">
            <label>Custom Group1</label>
            <field id="custom_field1" type="text" translate="label comment" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="0">
                <label>Custom Field 1</label>
            </field>
        </group>
    </section>
</system>

2
  • 3
    Is there a list of default options? – TheRealJAG Sep 11 '18 at 7:04
  • how to add under Customer Tab instead of under sales? – jafar pinjar Feb 28 '19 at 11:41
1

You can create new tab under Sales Configuration Like this:

Vendor/Modulename/etc/adminhtml/system.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>

        <section id="orderprocessing" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
            <class>separator-top</class>
            <label>Order Processing</label>
            <tab>sales</tab>
            <resource>TrainingJaymin_OrderProcessingFee::helloworld_config</resource>
            <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>Order Process Fee Configuration</label>
                <field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Module Enable</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="display_text" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Display Text</label>
                    <comment>This text will display on the frontend.</comment>
                </field>
            </group>
        </section>
    </system>
</config>

To define its rules:

Vendor/Modulename/etc/config.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <helloworld>
            <general>
                <enable>1</enable>
                <display_text>Hello World</display_text>
            </general>
        </helloworld>
    </default>
</config>

Now this will create a new tab named Order Processing Tab under Sales with having 2 fields one as a dropdown and other as a text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.