Magento is an open-source content management system for e-commerce websites. It is possible for developers to create custom modules for Magento. Magento create module is a complex yet wonderful process.
The first step involved with creating a custom Magento module is to identify a namespace and module name. The naming schema is “Namespace_Module”. The namespace generally used will be your company name. So if your company name is Connect, and you are creating a module One, then the full module name will be Connect_One. Magento’s own modules are named with the namespace, Mage. But you can also use the name Mage in your code under the local folder.
You can also create your module under core or community folder, apart from local.
In Magento, directory and file structure is very important. So if you are creating custom Magento module, you will be creating it inside the “/app/code/local” directory inside the Magneto installation. So if you are creating a Connect_One module, then the folder structure will be like this :
[Your Magento Install Folder]/app/code/local/Connect/One
In order to activate a module or inform Magento about your module, you will have to add an xml file to the directory, /app/etc/modules. The name of the xml file should be NamespaceModule.xml. So for ConnectOne, it will be Connect_One.xml.
This xml file will contain configuration for your module like module name, active status and code pool. The codepool will denote the location of your module. So Connect_One.xml will contain the following :
<config> <modules> <Connect_One> <active>true</active> <codePool>local</codePool> </Connect_One> </modules> </config>
If you did the above mentioned steps correctly, then you will see your new module listed in the list of modules to disable. To check this, you will have to see the “Disable Module Output” settings box under the System > Configuration > Advanced option under your Magento admin login.
Sometimes if your shop caching or compilation is enabled, you may not see your changes. In that case, please make sure you flush the cache or recompile the files using the admin options.
Next we are going to see the contents for your module directory. Your module directory will contain the following folders based on the functionality of your module.
Block : This folder is used to store View classes. These files will link data from Models to template files.
controllers : This folder contains the controller classes, which provides the business logics for the module.
etc : This is the only required folder in Magento custom module development. All module configuration xml files need to be placed here including the config.xml file.
Helper : This folder is used to store helper classes, which will contain different utility methods, that can be called from any point of Magento. It will be called by just the module name.
Model : This folder will contain the files which work with different data. These files are normally used to connect to database and save/retrieve data.
sql : This folder will contain files that are processed on module installation and upgrade like creating or updation of database or tables.
The Most important file that is required for a Magento module is the module configuration file named config.xml, which should be there in the “etc” folder.
A basic config.xml file will contain the module name and the version code. The config.xml file for Connect_One module will look something like this :
<config> <modules> <Connect_One> <version>184.108.40.206</version> </Connect_One> </modules> </config>
Other contents for this file will be based on your module. The etc folder may also contain a file name system.xml if your module uses the Magento’s configuration section.
Naming Convention of Magento class
Magento create module will definitely include creation of Magento classes. There is a naming conventions that you need to follow for Magento classes.
First, the Magento class name will include the whole directory path of the file, ending with the filename in most cases.
If the class extends any Magento core class, then you will have to use the extends keyword like this :
class YourCompanyName_ModuleName_FolderName_FileName extends MageClassName
These are the basic things that you need to understand before starting to create a custom Magento module.
Schogini assures 24x7 - 6 hour turn around ticket response time and 24 hour Email response time (firstname.lastname@example.org)