Website Maintenance Guide: Essential Tips to Keep Your Site Running Smoothly
October 28, 2024 10:41 am
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.
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.
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/
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
{
}
?>
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)
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>
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>”;
?>
(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>
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.
To do this, see below.
<?php
echo $this->getLayout()->createBlock(‘manageproducts/manageproducts‘)
->setBlockId(‘manageproducts‘)->toHtml() ; ?>
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”}}
www.example.com/index.php/manageproducts
You just have to replace the frontName(manageproducts) with the one you defined in the config.xml file.