Magento set default value for config defined value


Magento set default value for config defined value


Add the following code in your config.php file under the tag.

<default>
    <yoursection>
        <yourgroup>                
            <yourfield>My Default Value</yourfield>         
        </yourgroup>      
    </yoursection>
</default>

Example :

system.xml file

<?xml version="1.0" ?>
<config>
    <tabs>
        <Your_tab module="your_module" translate="label">
            <label>New Settings</label>
            <sort_order>309</sort_order>
        </Your_tab>
    </tabs>
    <sections>    

      <demosection module="your_module" translate="label">  
                <label>New Settings</label>
                <sort_order>352</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>1</show_in_store>
                <tab>Your_tab</tab>
                <groups>
                <demo_group translate="label">
					<label>New Settings</label>
					<comment></comment>
                    <sort_order>12</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <demo_field translate="label tooltip comment">
                            <label> - Add a value</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>
			    <comment>Your settings.</comment>
                        </demo_field>
                    </fields>

                </demo_group>
                
            </groups>
        </demosection> 

  </sections>
		
</config>

For Setting The default value of the field : demo_field you have to add following code in config.xml

<?xml version="1.0"?>
<config>
	<modules>
		<Your_module>
			<version>0.1.0</version>
		</Your_module>
	</modules>
        <helpers>
			<Your_module>
				<class>YourCompany_Your_module_Helper</class>
			</Your_module>
        </helpers>
      <adminhtml>
       <acl>
        <resources>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                 <demosection translate="title">
                                        <title>Settings </title>
                                        <sort_order>101</sort_order>
                                 </demosection> 
                                </children>
                            </config>
                        </children>
                    </system>
                 </children>
            </admin>
        </resources>
     </acl>
     </adminhtml>
    <default>
    <demosection>
        <demo_group>                
            <demo_field>1</demo_field>         
        </demo_group>      
     </demosection>
</default>
</config>

Which will look with default value 1 as :

magento set default value for config defined value

magento set default value for config defined value


Advertisements

Add Comment

📖 Read More