How to Add a Custom Module for Custom Admin Config Options
This wiki article is originally a blog post on my Pratthost Developer Zone Blog.
In my previous post, I showed you how to add instructions to the Short Description on the product add/edit form. While this is useful, if you ever wanted to change the instructions, you would have to open the template file and edit it manually. Wouldn’t it be nice to edit those instructions right in the admin configuration options? Yes, it would!
It’s quite simple to do - and it should only take you a few minutes to implement this. But, the options are endless. You can add all sorts of custom configurable options that you can edit in the admin panel very easily.
To get started, you’ll want to create a new module XML file similar to this: /app/etc/modules/MyMods_All.xml. Put the following code in that file:
- <?xml version="1.0"?>
When you have saved that file, create the directory structure for your new module like this:
Now, create this file: /app/code/local/MyMods/ExtraConfig/etc/config.xml and put the following code within it:
- <?xml version="1.0"?>
- <!-- no dependencies -->
- <models />
- <resources />
- <extraconfig />
- <blocks />
Next, create this file: /app/code/local/MyMods/ExtraConfig/etc/system.xml and put the following code within it:
- <backend translate="label">
- <short_desc_instructions translate="label">
- <label>Short Description Instructions</label>
When you have all of that done, login to the admin of your site. Browse to System→Configuration and on the left at the bottom, click on “Advanced”. You should see your new module on this list. Then, click on “Catalog” on the left, and you should see your new “Backend” configuration there. Populate that field with the instructions, and save it.
Now, open your elements.phtml file that you edited from the previous post (or open ANY template file that you want this information displayed). Remove the instructions, and replace them with this:
- <?php echo Mage::getStoreConfig('catalog/backend/short_desc_instructions') ?>
Once that is done - you should be all set! That’s all there is to it. No database work necessary - Magento covers all that for you. If you want a better look at how to setup the system.xml file, there are loads of examples right before your eyes. Simply go into any of Magento’s core modules (/app/code/core/Mage/) and open up their etc/system.xml file and have a look. You’ll easily figure out how to create different elements and how and where you can place them in different areas throughout the admin section.