Sometimes I want to add custom fields in magento admin configuration section through custom module and I want set the default value which post I have called as “Default value for admin field of custom module in magento”.For that I need to have a system.xml file having all the fileds inside my custom groups of custom section.Suppose, I have the following system.xml file. System.xml file is necessary to add admin configuration options.Here I have set my configuration section under catalog tab.

/app/code/local/NameSpace/ModuleName/etc/system.xml

.Set yout default value for configuration filed in magento.

<?xml version="1.0" encoding="UTF-8"?>
<config>
   <sections>         
        <customsection translate="label" module="custommodule">
            <label>Custom Section</label>
            <tab>catalog</tab>
            <frontend_type>text</frontend_type>
            <sort_order>110</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store> 
            <groups>
                <customgroup translate="label" module="custommodule">
                    <label>Custom Group</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>99</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <customfield translate="label comment">
                            <label>Custom Field</label>                         
                            <frontend_type>text</frontend_type>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </customfield>                      
                    </fields>
                </customgroup>
            </groups>           
        </customsection>            
    </sections>
</config>

Now, to add Default value for admin field of custom module in magento, you need to write the following in config.xml file of your module.

/app/code/local/NameSpace/ModuleName/etc/config.xml
<config>
    
    ...........
    ...........
    
    <default>
        <customsection>
            <customgroup>                
                <customfield>Custom Default Value</customfield>         
            </customgroup>
        </customsection>
    </default>
    
    ...........
    ...........
    
</config>
Default value for admin field of custom module in magento
Tagged on:             

Leave a Reply

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