How to add a new field to Magento configuration?

How to add a new field to Magento configuration?

Magento’s configuration system is highly flexible, allowing developers to add custom settings for better control over store functionality. Whether you need to introduce a new option in the admin panel or modify an existing configuration, Magento provides a structured way to extend its settings. In this guide, we’ll walk through the process of adding a new field to the Magento configuration, ensuring it appears in the admin panel and is easily accessible in your code.

Let’s get started!

In this example, I am going to add a new field under the Configuration -> CATALOG -> Catalog -> Product Alerts, The filed name is “some text” and it is a select box with Yes, No Options.

To do that, we need to add/edit system.xml in our custom module. Here is the XMl to add a new filed.

<?xml version="1.0"?>
<config>
    <sections>
        <catalog>
            <groups>
                <productalert>
                    <fields>
                        <test_field translate="label">
                            <label>some text</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>6</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </test_field>
                    </fields>
                </productalert>
            </groups>
        </catalog>
    </sections>
</config>

Thats it, Clear the Magento cache and test it. You will be able to see the changes.

How to add a new field to Magento configuration?