Create configuration for your Magento extension

Create configuration for your Magento extension

Today I’m going to give you and quick HOW-TO for beginners on how to create simple configuration for your extension inside Magento’s configuration section.
If you’re interested, read on:

Well, fist you need an extension that you’re going to build configuration for. If you’re new to Magento and you don’t know how to create an extension of your own, there’s a bunch of articles on this site about that, but my suggestion is to start on fresh extension, for testing..

And now, on to the fun stuff. First, you need to add (or edit) your system.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <tabs>
        <inchoo translate="label" module="mymodule">
            <label>Inchoo Extensions</label>
            <sort_order>100</sort_order>
        </inchoo>
    </tabs>
    <sections>
        <inchoo translate="label" module="mymodule">
            <label>Extension Options</label>
            <tab>inchoo</tab>
            <sort_order>1000</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
 
            <groups>
                <inchoo_group translate="label" module="mymodule">
                    <label>My Extension Options</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>1000</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
 
                    <fields>
                        <inchoo_input translate="label">
                            <label>My Input Field: </label>
                            <comment>My Comment</comment>
                            <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>
                        </inchoo_input>
                        <inchoo_select translate="label">
                            <label>My Dropdown: </label>
                            <comment>Source model provider Magento's default Yes/No values</comment>
                            <frontend_type>select</frontend_type>
                            <sort_order>90</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                        </inchoo_select>
                    </fields>
                </inchoo_group>
            </groups>
        </inchoo>
    </sections>
</config>

Then, in order to use Magento’s configuration section, you need to add (or edit) your extension’s config.xml file, and define models and helpers locations.

<config>
    <modules>
        <Inchoo_Mymodule>
            <version>0.1.0</version>
        </Inchoo_Mymodule>
    </modules>
    <global>
        <models>
            <mymodule>
                <class>Inchoo_Mymodule_Model</class>
            </mymodule>
        </models>
        <helpers>
            <mymodule>
                <class>Inchoo_Mymodule_Helper</class>
            </mymodule>
        </helpers>
     </global>
</config>

And finally, you need to edit your extension’s config.xml file again, in order to avoid “Permision denied.” problem.
Insert this part of XML into inside “<config></config>” tags:

<adminhtml>
    <acl>
        <resources>
            <all>
                <title>Allow Everything</title>
            </all>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <inchoo>
                                        <title>Inchoo - All</title>
                                    </inchoo>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>
</adminhtml>

And if you’ve done everything correctly you should see something like this:

To retrieve data saved in your configuration, you should use something like this:

Mage::getStoreConfig('inchoo/inchoo_group/inchoo_input',Mage::app()->getStore());

Or this:

Mage::getStoreConfig('inchoo/inchoo_group/inchoo_select',Mage::app()->getStore());

And with that, I’d conclude this one!

Get in touch to get your store in the best possible shape – our team of experts would be happy to check out your site and create a detailed customized report based on our Magento Technical Audit!

Related Inchoo Services

You made it all the way down here so you must have enjoyed this post! You may also like:

Magento 2 Webhook Notifications Deni Pesic
Deni Pesic, | 0

Magento 2 Webhook Notifications

Magento 2 Product Quick View Tomas Novoselic
, | 6

Magento 2 Product Quick View

Inchoo Flickr Gallery Magento Extension Srdjan Stojiljkovic
Srdjan Stojiljkovic, | 44

Inchoo Flickr Gallery Magento Extension

29 comments

  1. Could you please add “Download project as ZIP” to your tutorials. That would be really handy.

  2. As you suggest i have implemented code but complete work is not done.Left panel tab is created but on click of tab’s sub menu 404 error display’s and says page not found..Please help me

    1. Create a file adminhtml.xml in ‘app/code/{codepool}/{module}/etc/’

      Add the following code:

      <config>
          <acl>
              <resources>
                  <admin>
                      <children>
                          <system>
                              <children>
                                  <config>
                                      <children>
                                          <inchoo translate="title" module="inchoo_mymodule">
                                              <title>inchoo</title>
                                              <sort_order>999</sort_order>
                                          </animals>
                                      </children>
                                  </config>
                              </children>
                          </system>
                      </children>
                  </admin>
              </resources>
          </acl>
      </config>
  3. how to you get the url in case of an image?

    Main Image
    file
    adminhtml/system_config_backend_file
    media/alcomate
    04
    1
    1
    1

  4. Thanks for the article, however i have a question, where we load in the default yes/no config for a select menu / dropdown. The field ALWAYS defaults to Yes. This is due to the load order (i suspect) as it always loads options in a Yes then No order, there is no option for “Please Select” or from what i can tell, a way to reverse the load order.

    Any ideas?

  5. Am new to magento.. so i want detailed explanations for creating extensions…so any one let me know ..thanks in advance…

  6. <global>
            <sales>
                <quote>
                    <totals>
                        <fortest>
                            <class>fortest/quote_address_total_fortest</class>
                            <after>tax_subtotal,tax,subtotal</after>
                        </fortest>
                    </totals>
                </quote>
            </sales>
        </global>

    What does it mean?

  7. Ian, thanks for the tip. I’d been through my code for the 10th time, cleared cache, etc before trying to logout. That did the trick!

  8. If getting 404 error try logging out of the Magento admin because ACL rules are cached with your session.

    1. I’m also facing the same issue. if anyone had solved this, please help out me.

  9. I got it working. I have NO IDEEA how 😐
    I followed Find_Feed module config.
    It is possible that I got it working by changing

    Inchoo_Mymodule_Helper

    to

    Inchoo_Mymodule_Helper

    in config.xml and

    Inchoo Extensions
    100

    in system.xml respectively.

    Notice the change of “mymodule” to “inchoo_mymodule”.

    However, I can’t say that this is the solution, because after that I changed it back and it still works.
    Also I tried to move my module to the community codePool and moved it back after getting it working, surprisingly still works even after logout.
    Also once I added this

    something here

    immediately after the tag. That time I had my section in general tab. After switching back to my tab, and deleting this code, it still works.

    Once again, I don’t know what exactly solved my issue.

    As a tip, I suggest to log-out/in-s frequently, preferable after each change.

    Hope it helps.

  10. I second the 2 above posts. I’m having issues with installing majority of Extensions. The extensions install find, but when I try to go into configuration, It shows 404. I only found 1 that seems to work at the moment, rest is not working. Does anyone have any idea?

    Magento 1.5.1.0 , Magento Downloader 1.5.0.1 (which came with the new full version of magento)

    -Mike

  11. Hi all!
    I can confirm the derhecht’s problem. I’m using Magento 1.5.1.0 and it seems that we have the same problem. Can anyone take a look?

  12. I always get -404- when clicking on my new menu item. Any ideas? I followed your and Ivans guide with same result.

    The input of an menu item in an existing tab works fine ( etc. instead of ).

    I using Magento 1.5.0.1!

  13. @emilien – thanks for the info!
    @Ivan and @Andrey – sorry for the typos. I was rearranging code snippets, and have overseen those.

    Also, @Ivan – I didn’t want to over complicate anything since article was intended for complete beginners, and lots of XML can be confusing.

    And to @Andrey, it’s great idea to extend this one. In close future – I hope.

  14. The file name in “First, you need to add (or edit) your config.xml file.” must be fixed to “system.xml”

    And small mistake (duplication) there: “Then, in order to use Magento’s configuration section, you need you need…”

    Well, article better be extended – it just makes some magic things and doesn’t explain what they do. The people, looking for info on how to build extension, will find too small portion of it in this post.

  15. Hi Mladen,

    Seems you have typo in the article:
    “And now, on to the fun stuff. First, you need to add (or edit) your config.xml file.”. In config.xml stored another type of data, custom configuration fields always are stored in system.xml file.

    Also defining of custom ACL and Menu Items in config.xml was deprecated since 1.4.0, now you should use adminhtml.xml file for it.

    You can find more concerning system.xml and adminhtml.xml in the following articles:
    http://www.ecomdev.org/2010/10/27/custom-configuration-fields-in-magento.html
    http://www.ecomdev.org/2010/10/28/defining-acl-resources-custom-and-admin-menu-in-magento.html

    Configuration fields are defined in system.xml not in

    You can find the full reference of system.xml with detailed explanation of what each does

  16. You can set default value for each configuration key by adding in the config.xml file :

    <?xml version="1.0"?>
    <config>
        <default>
          <inchoo>
             <inchoo_group>
    	    <inchoo_input>default value</inchoo_input>
             </inchoo_group>
          </inchoo>
       </default>
    </config>

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.