Magento allow us to configure and tweak the behavior of the site in the admin panel via system configuration. We can extend and use this feature in our custom modules too. This article describes the steps to achieve custom configuration in magento admin panel In this article We create and save our custom configuration message in our module. This module creates a custom tab and allows us to configure our own settings.
Step 1: First we start with the modules config.xml.
app/code/local/Mydons/Configdemo/etc/config.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<?xml version="1.0"?> <config> <modules> <Mydons_Customconfig> <version>0.1.0</version> </Mydons_Customconfig> </modules> <global> <helpers> <customconfig> <class>Mydons_Customconfig_Helper</class> </customconfig> </helpers> </global> <adminhtml> <acl> <resources> <admin> <children> <system> <children> <config> <children> <mydons translate="title" module="customconfig"> </mydons> </children> </config> </children> </system> </children> </admin> </resources> </acl> </adminhtml> </config> |
Step 2: Create a Helper class as specified in the config.xml.
app/code/local/Mydons/Configdemo/Helper/Data.php
1 2 3 4 5 6 |
<?php class Mydons_Customconfig_Helper_Data extends Mage_Core_Helper_Abstract { } |
Step 3: To Create our own configuration setting, system.xml file needs to be created as shown below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<config> <tabs> <mydons translate="label" module="customconfig"> <label>Mydons</label> <sort_order>100</sort_order> </mydons> </tabs> <sections> <mydons translate="label" module="customconfig"> <label>Mydons Config Demo</label> <tab>mydons</tab> <frontend_type>text</frontend_type> <sort_order>100</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> <groups> <mydonsconfigdemo translate="label"> <label>Mydons Config Demo</label> <frontend_type>text</frontend_type> <sort_order>10</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> <fields> <mydons_message translate="label"> <label>Mydons Message</label> <frontend_type>text</frontend_type> <sort_order>10</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </mydons_message> </fields> </mydonsconfigdemo> </groups> </mydons> </sections> </config> |
Step 4: Now finally our module activation file
Mydons_Configdemo.xml needs to be placed in
app/etc/modules/Mydons_Configdemo.xml
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0"?> <config> <modules> <Mydons_Customconfig> <active>true</active> local </Mydons_Customconfig> </modules> </config> |
Step 5: Now to Retrieve the Configuration file drop a file name configtest.php in magento root directory.
http://example.com/configtest.php
Execute the file in the URL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php $mageFilename = 'app/Mage.php'; require_once $mageFilename; umask(0); Mage::app(); echo "<p style=color:green>"; echo Mage::getStoreConfig('mydons/mydonsconfigdemo/mydons_message'); echo "</p>"; |
Compatability :- Magento 1.4,1.5
0 Comments Leave a comment