Creating a Magento Extension from Scratch

What You Need To Know About Creating Your Own Magento Module

Many developers have started using Magento, a feature-rich open-source E-commerce solution. Since it has gained popularity, numerous community extensions or modules have surfaced and become available on Magento stores. But what if your store has specific needs or requirements and you can’t find a Magento module that works the way you want it to? The solution is simple: build it yourself. You can create your own module from scratch to suit the specific needs for your e-commerce website.

Before you create your own Magento module for your store, you need to first understand the basics of what goes in to a module and how it works. This way you can strategically plan what elements and functionality you want to include in your own module and how you can bring it to life. Here’s a short tutorial to guide you on how to create your own Magento module.

Disable the Cache

When writing modules, one of the best practices we should always keep in mind is to disable the cache. You can do this by simply going to: Admin > System > Cache Management > Select all > Actions > Disable > Submit.

The App/Code Directory

All of the original Magento modules are found inside the App/Code directory which provides the base functionality of the system. Basically, the brains of Magento can be found in the individual modules inside the directory. These individual modules are classified into three groups: the Core, Community and Local.

/app/code
|- /core/
|- /community/
|- /local/

Core

When writing a Magento module, we have to modify some files or build them from the ground up. When doing so, keep out of the app/code/core directory – files inside of this directory should not be modified. The reason for not modifying files inside this directory is to keep your application in-tact upon upgrading so as not to overwrite the core files you just altered.

Community

This directory found in app/code/community is where files end up when you install Magento modules from third party developers through the built-in installer “Magento Connect.” You can place files here when creating a module but a better technique is to put all your own modules in the local directory.

Local

The directory app/code/local is created empty after a fresh Magento installation. This is where we put the custom modules we will be creating. All development is generally performed here.

Module Namespace

“namespace” is the first directory you will create inside your local (app/code/local). This can be anything you like but it should not contain spaces and underscores.

Module Name

Module names and directory names are case-sensitive so take note of capitalizations and naming conventions. Give them logical names for easy organization. For example, if the module we will write is for the creation of a navigation menu for catalog, the logical name would be “CatalogNavigation” or “CatalogMenuNavigation”.

 

Now that you know the basics for creating a Magento Module, go try it yourself. If you’d like a more detailed guide for creating a custom module click here.

 

Jerome Rosal

He’s the self-proclaimed night-shift office DJ and knows how to put a smile on everyone’s face with his hilarious playlists. But when he’s not knocking it out of the ballpark in the office.