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 you need to build your own custom module in Magento? Here is a step by step guide for Magento module development.
Before you start 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 Magento module as well as the file system.
1. Create your own Magento module xml file
Create an xml that will tell Magento that the module is active and is readily available in local codePool.
Once you are done with this, check the Magento Admin Panel if you can be 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 Magento module
Although you won’t need to use all of the folders listed below all the time, you will have to create them beforehand. Always be consistent in naming your folders. The most ideal format is to use capital for the first letter and then set the rest in lower case.
3.Make a block class
Follow below code when making a block class. You can have two or more.
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.
class Pw_Manageproducts_IndexController extends Mage_Core_Controller_Front_Action
public function indexAction()
5. Define your config.xml file
In order to do this, just follow this:
<?xml version=”1.0” encoding=”UTF-8“?>
6. Make a template file
The template file will be used to render html. Remember to use only lower case letters for folder and file name.
echo “<h1>We are going to manage our magento products…</h1>”;
7. Make the layout.xml file
<block type=”manageproducts/manageproducts” name=”manageproducts” template=”pw/manageproducts/manageproducts.phtml”/>
For this file, the path is defined in the config.xml file. If you want to change the location, it is up to you.
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.
->setBlockId(‘manageproducts‘)->toHtml() ; ?>
2. Use it in CMS Content Editor. If you choose to use this way, you do not have to make the layout.xml file.
3. Through a URL
You just have to replace the frontName(manageproducts) with the one you defined in the config.xml file.