A lot many modules and community extensions are available for the feature-rich e-commerce solution, Magento. But what if they do not work as expected? It is absolutely essential to better understand the structure of a Magento module to the point that you could either modify it to suit your business needs or create your own module from scratch.
Before getting ahead with the basics of creating a Magento module, let’s assume that you already have installed Magento, running either on a development server or locally, to be able to add more files to it. Some of the most important elements of this tutorial include:
Disable the Cache
This is the first lesson to be learnt by a Magento development professional. Disabling the cache can be done by going to Admin Panel → System → Cache Management → Select All → Actions: Disable → Submit. The cache is a developer’s enemy as most of them face problems when a cached copy of their website is displayed by Magento instead of the updated one.
The App/code Directory
The app/code directory divided into core, community and local is where the real brains of Magento integration lie. Core is better kept off-limits as its files should not be modified. Modules provided by third parties can be found and are stored at app/code/community. The empty local directory is where one can add bespoke modules and this is where we are going to work for the rest of the tutorial.
Structuring our Directory
New directories and files can be added by opening your favorite editor and navigating to app/code/local. The first directory we create here is in the name of the company or the author’s module. The name of the second one can be more descriptive one. The directory and its name are case sensitive hence capitalize where essential for a better Magento customization.
Configuring our Module
Configuring our module is the next step. The directory named etc contains the configuring files, which is to be created with a new XML file. This XML file will inform Magento integration about several things like the files’ location in our module, version number and the events to observe.
Activating our Module
The next step is to create a new XML file in app/etc/modules. This is to inform Magento application that our module exists. By mow we have a new module that is enabled in Magento. Do a sanity check by logging onto the Magento admin panel, navigating to to System → Configuration → Advanced → Advanced and viewing the “Disable Modules Output” listing. Your module should be enabled here.
Defining an Event Observer and Configuring our Model’s Directory
To observe the event dispatched by Magento, just after saving a product, use code catalog_product_save_after. It is one of the cleanest and the best ways to extend the functionalities of this platform without having to override or rewrite any of its core lessons. Updating config.xml is essential to inform Magento where to find models in this module. Please visit : http://www.magentoauthority.com/magento-integration.php