Lesson 5.1: Create Magento Modules

Create and Upgrade Magento Module - magento open course

Howdy friends! Welcome back to Magestore’s Magento Tutorial series.

Last week we have learned about Configuration and naming in Magento. Lesson 5 will cover an interesting topic: How to create and Upgrade Magento Modules.

Lesson 5.1 Create a Magento Module

Lesson 5.2 Upgrade Magento Modules

As you know, Magento is a built on top of the Zend Framework. The Zend Framework supports modularizing your application, and Magento went the way of the module as part of its core design. In this short Magento Open Course lesson, I will explain how to use the Module Creator to help you create modules quickly.

Read more: Magento 2 news 2016

Creating new Magento Modules by using Module Creator

The Module Creator allows you to fill in a few questions (Module Name, Namespace, Magento Root Dir, and some Design questions), and then will auto-generate all the files necessary to get you started on your module. The coolest thing about the Module Creator is the way you can create templates/skeletons/frameworks of modules and store them for later use. Module Creator is generally a time saver and recommended for a noob.

Step 1:

Using a browser, download the latest full released archive file from https://github.com/shell/Magento-Module-Creator
On your computer, extract Module Creator from the downloaded archive. For Module Creator has a folder named ModuleCreator containing all of the Module Creator files will be created

Step 2:

Copy magento folder after extract Module Creator from the downloaded archive to xampp\htdocs

Step 3:

Using a browser, enter the url: to start creating new Magento Modules.
Please fill information for Namespace and Module(Module name)
Eg: Namespace: Magestore
Module: lesson05
Magento Open Course - Create and Upgrade Magento Module

Step 4:

Click “Create” button, the all source codes of new Magento Modules will be generated in xampp\htdocs\ModuleCreator\new
After create new Magento Modules Studentmanager by using Module Creator, we can see:
Magento Open Course - Create Module Magento

  • Declare Magestore_Lesson05 module in file app/etc/modules/Magestore_Lesson05.xml
<?xml version="1.0"?>
<!--
/**
* Magestore
*
* Online Magento Course
*
*/
-->
<config>
<modules>
<!-- declare Magestore_Lesson05 module -->
<Magestore_Lesson05>
<active>true</active>
<codePool>local</codePool>
</Magestore_Lesson05>
</modules>
</config>
  • Declare module’s version information in file app/code/local/Magestore/Lesson05/etc/config.xml
<?xml version="1.0"?>
<!--
/**
* Magestore
*
* Online Magento Course
*
*/
-->
<config>
<modules>
<!-- declare module's version information -->
<Magestore_Lesson05>
<!-- this version number will be used for database upgrades -->
<version>0.1.0</version>
</Magestore_Lesson05>
</modules>
<global>
<!-- declare model group for new module -->
<models>
<!-- model group alias to be used in Mage::getModel() -->
<lesson05>
<!-- base class name for the model group -->
<class>Magestore_Lesson05_Model</class>

<!-- declare model lesson05 work with lesson05 table -->
<entities>
<lesson05>
<table>lesson05</table>
</lesson05>
</entities>
</lesson05>
</models>

<!-- declare resource setup for new module -->
<resources>
<!-- resource identifier -->
<lesson05_setup>
<!-- specify that this resource is a setup resource and used for upgrades -->
<setup>
<!-- which module to look for install/upgrade files in -->
<module>Magestore_Lesson05</module>
</setup>
<!-- specify database connection for this resource -->
<connection>
<!-- do not create new connection, use predefined core setup connection -->
<use>core_setup</use>
</connection>
</lesson05_setup>
</resources>
</global>
</config>
  • Lesson05 model: app/code/local/Magestore/Lesson05/Model/Lesson05.php

<?php
/**
* Magestore
*
* Online Magento Course
*
*/

/**
* Lesson05 Model
*
* @category Magestore
* @package Magestore_Lesson05
* @author Magestore Developer
*/
class Magestore_Lesson05_Model_Lesson05 extends Mage_Core_Model_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('lesson05/lesson05');
}
}

 

  • Lesson05 resource model:app/code/local/Magestore/Lesson05/Model/Mysql4/Lesson05.php
<?php
/**
* Magestore
*
* Online Magento Course
*
*/

/**
* Lesson05 Resource Model
*
* @category Magestore
* @package Magestore_Lesson05
* @author Magestore Developer
*/
class Magestore_Lesson05_Model_Mysql4_Lesson05 extends Mage_Core_Model_Mysql4_Abstract
{
public function _construct()
{
/* lesson05_id is primary of lesson05 table */
$this->_init('lesson05/lesson05', 'lesson05_id');
}
}
  • Lesson05 Resource Collection Model:app/codel/local/Magestore/Lesson05/Model/Mysql4/Lesson05/Collection.php
<?php
/**
* Magestore
*
* Online Magento Course
*
*/

/**
* Lesson05 Resource Collection Model
*
* @category Magestore
* @package Magestore_Lesson05
* @author Magestore Developer
*/
class Magestore_Lesson05_Model_Mysql4_Lesson05_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('lesson05/lesson05');
}
}

  • All file sql to install database of module inapp/code/local/Magestore/Lesson05/sql/lesson05_setup

 

Magento Open Course Create a Magento module

To this moment, I guess you have all know how to create new Magento modules. In the next article, we will go to part 2: Creating our Installer Script and learn to Upgrade Magento modules. For more Magento lesson, you can search on our blog with the tag Magento Open Course.

Follow up our blog! See you soon!

Previous lessons in Magento Open Course series:

Lesson 5.1: Create Magento Modules
1.5 (29.17%) 24 votes

Comments

  1. You should specify what did you do in your module and collection code . You explained nothing just gave code . Anyways good tutorial and include code explanation . Thanks ! 🙂

  2. Looks like the Module Creator you reference is severely dated and no longer generates proper files for latest Magento 1 versions (CC 1.9, EE 1.14). I know the article is pretty old too, so it makes since. But, I am just wondering which updated Module Creator you would recommend to perform this task here in 2016? Would also prefer to include CSRF/XSS Protection on Front-end Forms. Any suggestions to achieve that?

  3. Thanks to helps me i am going to start my business on Megento so please inform more information about megento

Leave a Reply

Your email address will not be published. Required fields are marked *