Oneupweb : Magento Module Development Part 1: Creating the module

Magento is a great eCommerce platform. It is extremely flexible. So flexible in fact that it is hard to know everything that is available to you as a developer. It’s even harder to know because the Magento community seems to keep its craft a secret… documentation is getting better, but it is sparse. Finding examples can be a chore. The best way to start developing extensions for Magento is to hop in and get your feet a little mucky.

In this first article, I am going to talk about what it takes to even get Magento to recognize your custom module.

What files and where?

The most important thing to remember is that the initialization magic happens in the “app” folder of your Magento installation.

Step 1: Create your configuration xml file for the module

Location: app/etc/modules
Let’s go ahead and create our module xml.

<config>
    <modules>
        <Oneupweb_ProductColorBox>
            <active>true</active>
            <codePool>local</codePool>
        </Oneupweb_ProductColorBox>
    </modules>
</config>

Please note the capitalization. It does matter. For example: codePool vs. codepool.
What does this all mean?

Oneupweb_ProductColorBox
The name of our module. This also reflects the path to our module using this pattern:
/app/code/{codePool}/Oneupweb/ProductColorBox where {codePool} is the value supplied to the module xml, in this case local
active
Is this module active, true enough, it is
codePool
Where your module files will reside /app/code/{codePool}

Go ahead and save the file as Oneupweb_ProductColorBox.xml.

Login to the Magento admin and head over to the System tab and click on the Configuration item. From there go to the “Advanced” tab on the left, and click the “Advanced” tab that is inside of that one to verify our module installed correctly:

BOOM. Our module is installed and recognized by Magento. The first battle has been won, but the war is not over!

Step two setup your module directory

As mentioned the directory structure for your module files follows the convention (referencing the module xml file from above):
/app/code/{codePool}/Oneupweb/ProductColorBox *Notice the underscore from the name becomes the directory separator

So go ahead and create the following directories:
/app/code/local/Oneupweb/
/app/code/local/Oneupweb/ProductColorBox

Within this folder we will be adding the typical directories (thought we may not use them all):
/app/code/local/Oneupweb/ProductColorBox/Block/
/app/code/local/Oneupweb/ProductColorBox/etc/
/app/code/local/Oneupweb/ProductColorBox/Helper/
/app/code/local/Oneupweb/ProductColorBox/Model/
/app/code/local/Oneupweb/ProductColorBox/controllers/
If your module does any kind of installation setup like creating tables then you will also have:
/app/code/local/Oneupweb/ProductColorBox/sql/

The following is a brief explanation of what these folders are for:

Block
This is where the Blocks used in managing views for your module will be stored
etc
This is the directory to store configuration xml files like config.xml or system.xml
Helper
Where you store, well…. helpers. Files that will help you manage data, additional functionality…whatever. Loaded with Mage::getHelper()
Model
Where you store data models used in your module. Loaded with Mage::getModel() or Mage::getSingleton()
controllers
Controllers are what handle the requests for your module. They are essential the pages of your module
sql
Contains installation scripts for your modules that need to create tables

Conclusion

This is the first step to getting your module going in Magento. If you want to download the module skeleton created in this chapter, you can grab it here Stay tuned for more in this series as we build our very own Magento module!