Manage Variable Configuaration in Magento
Suppose we want to manage any API key or any variable in magento .
We will see here how to manage any configurable variable from magento admin and how we can use these configurable variable in frontend section in any controller or model .
Let we want to Manage Twitter Oauth Consumer key and Consumer secret variable from magento admin. Because these variables are customer related section then we will manage both variables from customer configuration in magento admin.
To make this variables as configurable open App/Code/core/Mage/Customer/etc/system.xml
In this file you will see there is a <groups> tag paste the following code just after <groups> tag
<twitter_application_key> <label>Twitter Application Key</label> <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> <fields> <consument_key translate="label comment"> <label>Twitter Cunsumer Key</label> <frontend_type>text</frontend_type> <comment>Its the customer key by Twitter for Your Apps.</comment> <sort_order>1</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> </consument_key> <consument_secret translate="label comment"> <label>Twitter Cunsumer Secret</label> <frontend_type>text</frontend_type> <comment>Its the customer secret by Twitter for Your Apps.</comment> <sort_order>1</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> </consument_secret> </fields> </twitter_application_key>
Now To see editable form goto Magento Admin >> Systme>> Configuration
In the left side you will see under Configuration >> Customers >> Customer Configuration
You will see following sceen
When you save data in it then this data will be saved into Core_config_data table you will see in this table there are two more configuration automatically get added for each of the two values which you have created into system.xml file. Just take path name of your newly added configuration. We will use this path to get this configuration from frontend section .
To get Configuration from frontend section symply write
<em>$consumer_key = Mage::app()->getStore()->getConfig('<strong>customer/twitter_application_key/consument_key</strong>');</em>
Here “customer/twitter_application_key/consument_key” represents our Path taken above.
Chandra Shekhar
Latest posts by Chandra Shekhar (see all)
- Best practices for micro service design - January 23, 2022
- Spring Boot - January 23, 2022
- Java - January 23, 2022
Recent Comments