How to Add a Custom Module for Custom Admin Config Options

Last modified by Prattski on Fri, June 25, 2010 09:05
Source|Old Revisions  

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:

  1. <?xml version="1.0"?>
  2. <config>
  3.    <modules>
  4.       <MyMods_ExtraConfig>
  5.          <active>true</active>
  6.          <codePool>local</codePool>
  7.       </MyMods_ExtraConfig>     
  8.    </modules>
  9. </config>

When you have saved that file, create the directory structure for your new module like this:

  • /app/code/local/MyMods/ExtraConfig/
  • /app/code/local/MyMods/ExtraConfig/etc/

Now, create this file: /app/code/local/MyMods/ExtraConfig/etc/config.xml and put the following code within it:

  1. <?xml version="1.0"?>
  2. <config>
  3.     <modules>
  4.         <MyMods_ExtraConfig>
  5.             <version>1.0.0</version>
  6.             <depends>
  7.             <!-- no dependencies -->
  8.             </depends>
  9.         </MyMods_ExtraConfig>
  10.     </modules>
  11.     <global>
  12.         <models />
  13.         <resources />
  14.         <extraconfig />
  15.         <blocks />
  16.     </global>
  17. </config>

Next, create this file: /app/code/local/MyMods/ExtraConfig/etc/system.xml and put the following code within it:

  1. <config>
  2.     <sections>
  3.         <catalog>
  4.             <groups>
  5.                 <backend translate="label">
  6.                     <label>Backend</label>
  7.                     <frontend_type>text</frontend_type>
  8.                     <sort_order>50</sort_order>
  9.                     <show_in_default>1</show_in_default>
  10.                     <show_in_website>1</show_in_website>
  11.                     <show_in_store>1</show_in_store>
  12.                     <fields>
  13.                         <short_desc_instructions translate="label">
  14.                             <label>Short Description Instructions</label>
  15.                             <frontend_type>textarea</frontend_type>
  16.                             <sort_order>50</sort_order>
  17.                             <show_in_default>1</show_in_default>
  18.                             <show_in_website>1</show_in_website>
  19.                             <show_in_store>1</show_in_store>
  20.                         </short_desc_instructions>
  21.                     </fields>
  22.                 </backend>
  23.             </groups>
  24.         </catalog>
  25.     </sections>
  26. </config>

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:

  1. <?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.




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs