Adding configuration variables to Magento
Configuration variables in Magento control the setup an operation of your store, through the configuration settings in the admin portal. Creating new configuration variables and sections for your own modules is very straight forward.
Looking at the configuration for an existing configuration section, the Locale options in the General section.
So we can write the location of each variable shown as
config/general/locale/timezone
config/general/locale/locale
config/general/ locale/first
config/ general/locale/weekend
I have used only the first word of each name to simplify the path. Conveniently this maps to the xml that is used to build these variables; shown below.
<config> <sections> <general translate="label" module="core"> <label>General</label> <tab>general</tab> <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> <groups> <locale translate="label"> <label>Locale options</label> <frontend_type>text</frontend_type> <sort_order>8</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> <fields> <timezone translate="label"> <label>Timezone</label> <frontend_type>select</frontend_type> <source_model>adminhtml/system_config_source_locale_timezone</source_model> <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> </timezone> <code translate="label"> <label>Locale</label> <frontend_type>select</frontend_type> <source_model>adminhtml/system_config_source_locale</source_model> <sort_order>5</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </code> <firstday translate="label"> <label>First Day of Week</label> <frontend_type>select</frontend_type> <source_model>adminhtml/system_config_source_locale_weekdays</source_model> <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> </firstday> <weekend translate="label"> <label>Weekend Days</label> <frontend_type>multiselect</frontend_type> <source_model>adminhtml/system_config_source_locale_weekdays</source_model> <sort_order>15</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </weekend> </fields> </locale> </groups> </general> </sections> </config>
Looking at the first 4 lines it states that this is configuration data, the section tag shows that the next tag will be at the section level. The general tag is the identifier for the section. Imediately within this are a five tags which configure the section.
Following the section configuration is the groups tag. This indicates that the next blocks are groups. The locale tag is the identifier for the group. as with the section the next 6 tags set the properties for the group.
The fields tag then indicates that the following blocks represent the fields to show. Again the first tag is the idenitifer of the field, followed by tags to configure the field.
The configuration variables at the section and groups levels are
- label – The displayed text
- tab – which menu tab the section appears within
- frontend_type – always text for sections and groups
- sort_order – order of display lower number shows higher
- show_in_default – Show in the default view
- show_in_website – Show in the website level view
- show_in_store – Show in the store level view
configuration tags for field
- label
- frontend_type – field type – text, textarea, select, label, image, multiselect, time, password, allowspecific
- source_model – Model class to call for list data
- sort_order
- show_in_default
- show_in_website
- show_in_store
Example
The example module acme_mydispatch needs configuration variables to set the url to connect on and the user account details. This logically goes in the shipping section. The xml used is
<config> <sections> <shipping> <groups> <mydispatch translate="label"> <label>My Dispatch Connection data</label> <frontend_type>text</frontend_type> <sort_order>50</sort_order> <show_in_default>1</show_in_default> <show_in_website>0</show_in_website> <show_in_store>0</show_in_store> <fields> <url translate="label"> <label>url</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> </url> <user translate="label"> <label>User ID</label> <frontend_type>text</frontend_type> <sort_order>20</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </user> <secret translate="label"> <label>Secret Key</label> <frontend_type>password</frontend_type> <sort_order>30</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </secret> </fields> </mydispatch> </groups> </shipping> </sections> </config>
This creates the configuration settings shown below.

In the next post I’ll look at how to use the new variables we have just created.
Note – creating a new section requires a module to be defined, in version 1.2 this assumes the module is a mage_ module. this make screating custom tabs trciky and a topic for a future post.

One Response Leave a comment
Hi, sorry but where do I create this file in my new module folder structure?
Thanks