Let's Connect

Magento Module Development: A Detailed Guide For Magento Developers

Magento is undeniably the leading eCommerce platform today. One of the primary reasons behind this is the ever-growing community of Magento Developers. Although the Magento community edition already offers the basic features needed in setting up a functional e-commerce store, sometimes you need to create your own custom-made extensions or module.As a Magento developer, what should you do when building your own custom module in Magento? Here is a step-by-step guide for Magento module development.Before creating a custom module in Magento, be sure you already have completed Magento installation and have turned off caching and compilation. You also need to have at least basic knowledge about the directory structure of the Magento module as well as the file system.

Magento Module Development

1. Create your own Magento module XML can file

Create an xml that will tell Magento that the module is active and is readily available in local codePool.

<?xml version=”1.0″?>
<config>
<modules>
<Pw_Manageproducts>
<active>true</active>
<codePool>local</codePool>
</Pw_Manageproducts>
</modules>
</config>

Once you are done with this, check the Magento Admin Panel if you are able to see your module. You can also locate the Pw_Manageproducts module in System->Configuration->Advanced->Disable Modules Output.

2. Make a Directory Structure for the Magento Module

Although you won’t need to use all of the folders listed below all the time, you will still have to create them beforehand. Always be consistent in naming your folders. The ideal format is to use upper case for the initials and then set the rest in lower case.app/code/local/Pw/Manageproducts/
–controllers/

–sql/

–Block/

–etc/

–Helper/

3. Make a block class

Follow the below-mentioned code when making a block class. You can have two or more.(appcodelocalPwManageproductsBlockManageproducts.php)

<?php
class Pw_Manageproducts_Block_Manageproducts extends Mage_Core_Block_Template
{
}
?>

4. Prepare the front controller

You need to prepare an index controller if you need to call your Magento module through a URL. There is no need for you to create a backend module controller.

<?php
class Pw_Manageproducts_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
?>
(appcodelocalPwManageproductscontrollersIndexController.php)

5. Define your config.xml file

In order to do this, just follow this:
<?xml version=”1.0” encoding=”UTF-8“?>
<config>
<modules>
<Pw_Manageproducts>
<version>1.0.1</version>
</Pw_Manageproducts>
</modules>
<global>
<models/>
<blocks>
<manageproducts>
<class>Pw_Manageproducts_Block</class>
</manageproducts>
</blocks>
</global>
<frontend>
<routers>
<manageproducts>
<use>standard</use>
<args>
<module>Pw_Manageproducts</module>
<frontName>manageproducts</frontName>
</args>
</manageproducts>
</routers>
<layout>
<updates>
<manageproducts>
<file>pw/manageproducts.xml</file>
</manageproducts>
</updates>
</layout>
</frontend>
<default>
<manageproducts>
<product>
</product>
</manageproducts>
</default>
</config>

6. Make a template file

The template file will be used to render HTML. Remember to use only lower case for folder and file names.

(appdesignfrontenddefaultdefaulttemplatepwmanageproductsmanageproducts.phtml)
<?php
echo “<h1>We are going to manage our magento products…</h1>”;
?>

7. Make the layout.xml file

(appdesignfrontenddefaultdefaultlayoutpwmanageproducts.xml)
<?xml version=”1.0“?>
<layout version=”0.1.0″>
<manageproducts_index_index>
<reference name=”root”>
<action method=”setTemplate”><template>page/1column.phtml</template></action>
</reference>
<reference name=”content”>
<block type=”manageproducts/manageproducts” name=”manageproducts” template=”pw/manageproducts/manageproducts.phtml”/>
</reference>
</manageproducts_index_index>
</layout>

Magento Development Layout
You now have a new Magento module. But, if you are still not sure how to use the plugin, you may try one of these simple ways to use it.

1.Use it in a PHP file.

To do this, see below.

<?php
echo $this->getLayout()->createBlock(‘manageproducts/manageproducts‘)
->setBlockId(‘manageproducts‘)->toHtml() ; ?>

2.Use it in CMS Content Editor.

If you choose to do it this way, you do not have to make the layout.xml file.
{{block type=”manageproducts/manageproducts”
template=”pw/manageproducts/manageproducts.phtml”}}

3.Through a URL

www.example.com/index.php/manageproducts
You just have to replace the frontName(manageproducts) with the one you defined in the config.xml file.




1



1

Found this article helpful?

Happy 7 1