Crack The ‘HOW’ Of Your First Magento Module – Magento Plugin Development

Magento Module Development

We know that now you are aware about the fact that ‘Magento extensions are an integral part of Magento’. No doubt in market there are lot of extension available for making your Magento store feature-rich stored, but what if they don’t specify your particular requirement? Magento custom module development can be the answer to your trouble. But still tucked wondering what to do, what not, how to start?

We are here to serve the happiness of developing your first custom plugin! Let’s explore the ‘how’!!

Prior learning the creation process its good know about the Magento modules types. So Magento modules types are:

  • Core

Core is the default extension available in Magento and you can find by following this path:

[magentodirectory]/app/code/core/Mage folder or directory.

  • Community

Community extension is available for free and it can be accessed from different community website such as Magento Connect. Discover this extension with the following path:

[magentodirectory]/app/code/community/ [namespace]/ [extensionname]

  • Local

Local extensions are the one which are built by third-party resources to perform particular functions as per requirement. You can discover them in a folder or directory, the path is:

[magentodirectory]/app/code/local/ [namespace]/ [Extensionname].

  • Let’s Give Recognition To Module – Name It

Your first step is to name your module. Usually the names of Magento modules consist of two parts: <Namespace>_<Module>. In <Namespace> you can give author name or organization name and in <Module> you can give the desired Module name. Accordingly, we have given our modules name as xyz_myMagentomodule.

P.S. This name is used as a reference in this article.

  • Create Directories and Configuring Them

Great! You have given the name to your module. So now your next step is to set the directories. For that all you need to do is navigate your Magento installation direction and later go to app/code/local and start creating directories.

Wow! You have even created a directory! Now the next step is to configure and activate your module i.e. xyz_myMagentomodule in the app/etc/modules directory. This is the directory where all the config files for best ecommerce platform – Magento are stored.

<?xml version=”1.0″?>

<config>

<modules>

<xyz_MyMagentomodule>

<active> true </active>

<codePool> local </codePool>

</xyz_MyMagentomodule>

</modules>

</config>

Now run the above mentioned code, Magento will begin to detect the location of the created module. The <active> true </active> will enable the module. If everything goes well, you can effortlessly find your module in Magento Admin Panel > System > Configuration > Advanced > Advanced > Disable Modules Output list.

  • Get Set Go For Developing Your First Magento Extension

Developing First Magento Extension

  • Named it

  • Activated

So now it’s time to make module configuration file – which will inform Magento about its existence. For this, go to app/code/local/xyz/MyMagentomodule/etc and now you have to create a config.xml file. After creation add the following code:

<?xml version=”1.0″?>

<config>

<modules>

<xyz_myMagentomodule>

<version>0.1.0</version> <!– This is the version number of your module –>

</xyz_myMagentomodule>

</modules>

<frontend>

<routers>

<mymodule>

<use>standard</use>

<args>

<module>xyz_myMagentomodule</module>

<frontName>myMagentomodule</frontName>

</args>

</mymodule>

</routers>

</frontend>

</config>

Confused? Which tag played which role? Well not to worry, we will solve your doubts.

The first tag <module> includes the name and version number of your module. We have included the version number as it plays a significant role at time of updating the module.

So now what’s next? What role frontend tag plays? Well the <frontend> tag permits Magento to keep it informed about dispatched controls. Later you will find tag <routers>, which is helpful in defining the ways for accessing multiple controls with the help of routing function.

So next is <mymodule> we have defined the module name in that tag. The <frontend> is been used to access the frontend name of the module similar to name of your website.com/index.php/mymodule/index.

Now you need to create controller file and for doing that, go

to app/code/local/xyz/MyMagentomodule/controllers, and add the below code.

<?php

class xyz_MyMagentomodule_IndexController extends

Mage_Core_Controller_Front_Action

{

public function indexAction()

{

echo “Yupiee My First Magento Module”;

}

}

So now when you will access the URL of your website.com/index.php/mymodule/index, it will display “Yupiee My First Magento Module”. Amazing! You are a genius! You have successfully created your first Hello World Magento module.

  • Implementing Controller Dispatch

Great! Now just the thing left is to implement the controller dispatch. For that we need to extend Mage_Core_Controller_Front_Action class, this class incorporates every function which permits you to offer a specific path to the URL. The main function of the class is to tell the location of class file. This clears that Magento mirrors the location of class file. Hence we can say that the class

Mage_Core_Controller_Front_Action is stored in Mage > Core > Controller > Front >Action.php.

With the above discussion we can easily say that the name of our controller is xyz_MyMagentomodule_IndexController. Prior that ensure your Magento name is defined as (<module>tag)_(Action Controllername)(keyword Controller).

Hence the URL will be: website.com/index.php/frontendname/actionControllername/actionmethod

Finally! Last Stage! – Testing

So for testing, let’s create a test activity:

<?php

class xyz_MyMagentomodule_IndexController extends

Mage_Core_Controller_Front_Action

{

public function indexAction()

{

echo “It’s Perfect”;

}

public function testAction()

{

echo “test action”;

}

}

You can perform your test action through website.com/index.php/mymodule/index/test.

Superb! You have created your first module! We know the happiness of creating your first module can’t be measured right now. Congrats!

Leave a Reply