When customising the functionality of Magento you should always write it as it own extension unless you have a good reason not to. The behaviour of Magento extensions relies to a huge degree on a range of different xml files. In this series I will explain which xml file does what.
The very first thing when starting with your own extension is to tell Magento exactly that. All that is needed is for you to place a new xml file in app/etc/modules/. By convention you should name it NameSpace_ModuleName.xml. Below is an example
<?xml version="1.0"?> <config> <modules> <NameSpace_ModuleName> <active>true</active> <codePool>community</codePool> </NameSpace_ModuleName> </modules> </config>
And the second decision is how to name it. The naming corresponds to the folder structure Magento expects. In most cases you can read the underscore (_) as contains folder.
So for our extension we need to create a folder NameSpace and subfolder ModuleName.
Congratulations you have written your first extension. You can verify that it is working by going into the Magento back-end System > Configuration > Advanced and you will see NameSpace_ModuleName listed under Disable modules output.
You can turn off an extension completely by changing
This works for all extensions. See also this related quick tip.
Magento is very particular about naming. Unfortunately it is not well documented and a lot is translated/converted on the fly. My advice for your first extensions is to keep it simple and name everything lowercase or capitalized. Furthermore keep everything to one word. So instead of using NameSpace just use Name or Namespace. Instead of creating grand_total just use grandtotal.
Keeping with this tip your file naming is consistently:
All folder and .php files are capitalized rest lowercase
Magento convention is to keep all system.xml, config.xml and all .phtml completely lowercase
Once Magento knows about our extension we need to tell it what to do with it. This is where the next xml file the config.xml comes in which I will start taking apart in a next post.
Originally published on magebase.com. Copyright © 2010 Magebase - All Rights Reserved.