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"?> <config> <modules> <myMods_ExtraConfig> <active>true</active> <codePool>local</codePool> </myMods_ExtraConfig> </modules> </config>
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"?> <config> <modules> <myMods_ExtraConfig> <version>1.0.0</version> <depends> <!-- no dependencies --> </depends> </myMods_ExtraConfig> </modules> <global> <models /> <resources /> <extraconfig /> <blocks /> </global> </config>
Next, create this file: /app/code/local/MyMods/ExtraConfig/etc/system.xml and put the following code within it:
<config> <sections> <catalog> <groups> <backend translate="label"> <label>Backend</label> <frontend_type>text</frontend_type> <sort_order>50</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> <fields> <short_desc_instructions translate="label"> <label>Short Description Instructions</label> <frontend_type>textarea</frontend_type> <sort_order>50</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </short_desc_instructions> </fields> </backend> </groups> </catalog> </sections> </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:
<?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.
Again, let me know if you have any questions, troubles, or better ways to accomplish doing something like this. Enjoy!