Thứ Năm, 7 tháng 4, 2016

Magento Custom made Module Development

Magento custom module development is actually a core part of any Magento development or Magento venture, because at any stage you might like to integrate your own functionality/module inside your existing Magento project.

In this particular series, I am going to cover the important points of Magento custom component development.

If you want to go further along with your Magento development, check out the a comprehensive portfolio of useful Magento extensions about Envato Market.

Magento exts on Envato Market
Magento extensions on Envato Industry
Throughout this series, Now i'm referring Magento Community Release 1 . 7, though personalized module structures are the same in every versions of Magento. Before you go we're going to start actual element development, let's quickly understand basic structure of Magento.

Whenever you install a fresh Magento, you will notice the following Magento website directory structure:

Introduction to Magento MVC Structure

Like any other significant frameworks such as Joomla, CakePHP, CodeIgniter, etc ., Magento furthermore follows the MVC-based architectural mastery though this is little bit diverse from core PHP MVC structures. Here, I'll explain the in Magento architecture by simply comparing it with basic PHP MVC architecture.

PHP MVC architecture
In the standard MVC pattern, the movement of the application is this type of thing:

There is main entry point -- index. php - via where the entire app course-plotting mechanism is determined.
Based on this particular routing mechanism and required URL pattern, the iphone app will call the appropriate operator.
The controller then telephone calls the appropriate views.
Finally, the lovely view files collect the data by model files and exhibit the data.
Magento MVC buildings
Magento's MVC architecture brings a few layers to the MVC pattern, but the basic move of control of an application is much like this:

There is main entry way - index. php : from where the whole software package will be initialized.
Base around the requested URL appropriate remote will be called.
Controller identifies the pages and load design files for those pages.
Structure files tells the remotes which block files to utilize.
Block files collect your data from models and terme conseillé files and pass the idea to templates files.
Web templates files receive data and also render html.
Initially, this can be difficult to understand since it has a few extra layers. To obtain additional familiar with the flow connected with control, let's develop a customized "Hello World" module.

Prior to starting With Modules

I am let's assume that you already have a working copy associated with Magento with version 1 ) 7 or 1 . 7+ (or else as type does not matter at this stage)
Modify the cache. To Disable cache memory Go to Magento Admin Section > System > Cache Management > Select all cachette type from left side apprpriate boxes > Select Motion: disable from right leading drop down > simply click Submit.
The Structure of your Magento Module
Code Swimming pools
Magento contains three form of code pools where the just about all custom and core themes of Magento are exists.

Core pools contain each of the core modules which are automagically comes with a Magento installation. These kinds of modules are written by Magento developers. It's recommended never to modify these modules due to the fact whenever you will upgrade your Magento installation, all the core web template modules will be overwritten and your improvements will be lost.
Community regularly contain all the modules rapid that is, custom modules instructions that are developed by third-party computer programmers to be installed through Magento Connect. These modules typically extend core modules and gives their own functionality that can usually be used anywhere in Magento.
Regional pools contain all the custom made module that are going to be used for a certain project but are not readled in Magento Connect
Hence, we have two choice of costly: Community or Local. Given that we are working on our own undertaking, we are going to use a local pool area, though there's no restriction with using the community pool, both.


Magento modules contain the following components:

Blocks include functions that are used to present data in templates.
Types contain the business logic regarding modules.
Resource Models has functions that are used for repository interaction.
Controllers defines webpage layout and blocks data and are loaded when a LINK is requested.
etc consists of configuration files in XML formats which tells Magento how many files modules have got and how the module interacts.
Helpers contain functions which can be used for defining common enterprise logic (such as graphic resize, validation). These capabilities can used anywhere throughout the Magento application
sql includes SQL scripts to create, adjust, or delete SQL furniture.
Module Naming
We need to offer a name to our module. Typically, Magento module names are constructed of two parts: _ . The best training to give a Magento component a name is pick as a possible author or a company name along with as being a actual module name.

Based upon these naming convention, Me giving our module the particular Chiragdodia_Mymodule name. We will guide this name throughout this specific series.

Code Set Up in addition to Configuration
Lets create typically the directories base on previously mentioned structure. Go to your Magento installation direction then find the way to app/code/local and create often the directories as shown under.

Next, we will configure as well as activate our module by means of creating config file Chiragdodia_Mymodule. xml in the app/etc/modules listing. This directory contains config files for all modules.

This specific file will tell Magento about the location of our component. In the active tag, we certainly have specified true to enable the module. If everything is suitable thus far, then you will find your current module in the Magento Administrator Panel > Method > Configuration > Advanced > Advanced > Inhibit Modules Output list. After this you can enable and deactivate your module.

Starting: Development

Next we will generate our module configuration data file. This file will explain to Magento all about our element. This includes how many files each of our module contains, what type of documents (models, helpers, database classes), and so on.

Let's go through series by line to understand every single tag. Here, the first indicate is that contains the name and edition of our module. The model number is very important when it comes to changing your module update your component.

The tag will tell Magento about the controller dispatched. In the point, we have defined that tells Magento how to access our remotes via the routing device.

In the tag, we have defined element name in tag and frontend name in . By using a frontend name, we could access our module inside frontend like yoursitename. com/index. php/mymodule/index.

By calling yoursitename. com/index. php/mymodule or yoursitename. com/index. php/mymodule/index Magento look for index action of your respective module's controller file. As a result, we need to create our controlled file.

Go to app/code/local/Chiragdodia/Mymodule/controllers as well as file IndexController. php together with following content.

Note that each one file's name and school names are case very sensitive in Magento It's very essential that you are taking care in own naming your work when creating files and also classes.

school Chiragdodia_Mymodule_IndexController extends Mage_Core_Controller_Front_Action

public function indexAction()

echo "Hello tuts+ World";

Now open URL yoursite. com/index. php/mymodule/index it will printing "Hello tuts+ World". Wonderful - we're finally carried out with our first hello planet module.

Controller Dispatch
In this article we have extend the class Mage_Core_Controller_Front_Action that contains all the methods which can be using in routing regarding url. The Magento school name reflects the location of sophistication file. So the class Mage_Core_Controller_Front_Action resides in location Mage > Core > Controller > Front > Steps. php

See the class label of our controller that is Chiragdodia_Mymodule_IndexController. Magento controller to be known as in such a way that it reflects ( tag)_(Action Controllername)(keyword Controller).

tag = Chiragdodia_Mymodule (we have defined this kind of tag in config. xml)
Action Controllername = Listing
Action controller followed by the actual Controller keyword
Based on that pattern, the name of our control is Chiragdodia_Mymodule_IndexController

Now begin to see the URL pattern which is stick to the below route pattern
yoursite. com/index. php/frontendname/actionControllername/actionmethod

frontendname sama dengan mymodule
actionControllername = Index chart
actionmethodname = Index
Determined by this URL pattern, all of our module's URL is yoursite. com/index. php/mymodule/index/index. You can also it is easy to using yoursite. com/index. php/mymodule because whenever you have not particular an actionController or actionmethod name, Magento loads the particular index controller and list action by default.

Now why don't create one more action: testAction.

class Chiragdodia_Mymodule_IndexController extends Mage_Core_Controller_Front_Action

public function indexAction()

echo "Hello tuts+ World";

public function testAction()

echo "test action";

We could access the testAction making use of URL yoursite. com/index. php/mymodule/index/test. As explained earlier in this article

frontendname = mymodule
actionControllername = Index
actionmethodname sama dengan test
This is how the operator works in Magento.

Initially, it can be difficult to understand almost everything at once so I've incorporated all of the source code to the module so that you can review the item and implement your own perform while using it as a guide.

Exactly what is Next?

In next portion, we are going to fill in some templates in our module by producing layout and block data files. We will understand how the cool layouts files works in Magento and what role blocks enjoy within the context of Magento.

Until then create your very own module and let me know about anything that causes you difficulty.