Magento Extension Development (or Magento plugin Development) is always the highest priority for any Magento development as well as Magento projects. The reasons are mostly the high demand of Magento customization for extensions, or the necessity to integrate the module into a current Magento project.
In this post, we will cover a detailed overview of Magento custom extension development.
For better Magento extension development, you should check a huge category of Magento extensions from Magestore.
This tutorial guide is using Magento Community Edition 1.7, however the custom module structures of all versions of Magento are basically the same. In order to understand thoroughly the work of Magento extension development, we must first look through the basic structure of Magento.
A Magento directory structure always consist of these parts when you install a fresh Magento version:
Introduction to How MVC works in Magento
Magento also follow the same MVC framework like Joomla, CakePHP, however Magento stated clearly that Magento is a configuration-based MVC system. The alternative to this would be a convention-based MVC system.
The difference is, in a convention-based MVC system, anytime you want to add a new Controller or a new Model, you just need to create the file/class, and the system would pick it up automatically.
However, in a configuration-based system like Magento, you often need to carefully tell the system about the new class, or new group of classes beside adding the new file/class to the codebase. In Magento, each Module has a file named config.xml. This file contains all the relevant configuration for a Magento Module (or Magento Extension). At runtime, all these files are loaded into one large configuration tree.
Also, you will never code in index.php. In an MVC system, index.php will contain code/calls to code that does the following:
- Examines the URL
- Based on some set of rules, turns this URL into a Controller class and an Action method (called Routing)
- Instantiates the Controller class and calls the Action method (called dispatching)
This means the practical entry point in a MVC-based system like Magento is a method in a Controller file. Consider the following URL:
The Structure of Magento Extension
Magento contains three type of code pools consisting of all custom and core extension modules of Magento.
- Core pools contain all the Magento default modules which comes within a Magento installation. These code pools belong to the Magento core development team. So you should NOT make any modifications in these code pools because whenever you upgrade your Magento version, all the core modules will be overwritten and your modifications will be lost.
- Community pools contain all the custom modules that are developed by third-party programmers, for example installed through Magento Connect. These belong to Magento community developers (including any developers who develop third party extensions). These modules are much better than core modules and offer their own functionality to be used anywhere in Magento.
- Local pools contain all the custom module which can’t be found in Magento Connect. These can be used if you want to do any modifications (add new functionality/extension overriding/core functionality modifications etc.) specifically for your Magento store.
Note: Magento actually uses three code pools. It will load local first, community second, and core third.
Magento extensions consist of the following components:
- Blocks contain functions that are used to display data in templates. They help provide the data used in the View component of the module structure. Blocks coordinate models with the template files.
- Models contain the business logic of modules. Models are objects that contain database code for interacting with a type of data.
- Resource Models are objects that contain code that fetches data from a data store. In practice, this means a resource model is the object that contains the SQL building and fetching code, as well as references to objects that connect to the main Magento database.
- Controllers represent all business logic actions for the given request. These actions include dispatch(), preDispatch(), postDispatch() methods and delegate commands to other parts of the system.
- etc contains configuration files in XML formats which tells Magento how many files modules have and how the module interacts.
- Helper contain functions that are used for defining common business logic (such as image resize, validation). Helpers contain utility methods, which are commonly used throughout the application. Methods, as declared in helpers, can be called from any template file or block, model, controller class. Each module has a default Data Helper class Modulename/Helper/Data.php.
- sql contains SQL scripts to create, modify, or delete SQL tables.
Generally, Magento module names are made of two parts: <Namespace>_<Module>. The best practice to give a Magento module a name is choose <Namespace> as an author or a company name and <Module> as a actual module name.
Code Set Up and Configuration
Go to your Magento installation direction, navigate to app/code/local and create the directories.
Next, configure and activate the module by creating config file Magestore_OSCmodule.xml in the app/etc/modules directory. This directory contains config files for all modules.
In the active tag, we have specified true to enable our module. If everything is correct thus far, then you will find your module in the Magento Admin Panel > System > Configuration > Advanced > Advanced > Disable Modules Output list. From here you can enable and disable your module.
Magento Extension Configuration Development
Go to app/code/local/Magestore/OSCmodule/etc and create a config.xml file that will contain following content:
<version>0.1.0</version> <!-- Version number of your module -->
Go to app/code/local/Magestore/OSCmodule/controllers and create file IndexController.php with following content.
class Magestore_OSCmodule_IndexController extends Mage_Core_Controller_Front_Action
public function indexAction()
echo "Hello World";
Now open URL yoursite.com/index.php/oscmodule/index it will print “Hello World”. Finally, we finish the first module in our Magento extension development.
We also contribute great content of Magento Tutorial for Magento 1.x.
DON'T MISS THE CHANCE!