Create your first Magento 1.x module

This article will help you to build your first full functional Magento module.

Define the module

The first step is to define the module and the location of it in the code pool folder /app/etc/modules/<Namespace>_<Module>.xml

<?xml version="1.0"?>

<config>
    <modules>

         <Bb_Core>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
            </depends>
        </Bb_Core>


    </modules>
</config>

Create Controller

/app/code/local/<Namespace>/<Module>/controllers/IndexController.php
Create the controller in the module folder under the “controllers” directory.

<?php
class <Namespace>_<Module>_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
            $this->loadLayout();
            $this->renderLayout();
    }
}

Create Configuration XML

/app/code/local/<Namespace>/<Module>/etc/config.xml

You have to define this file to configure and define all resources needed in the module.

You can define into the configuration XML file the routes, blocks, models, translations, and others as shown in the following example:

<?xml version="1.0"?>
<config>
    <modules>
        <[Namespace]_[Module]>
            <version>0.1.0</version>
        </[Namespace]_[Module]>
    </modules>
    <frontend>
        <routers>
            <[module]>
                <use>standard</use>
                <args>
                    <module>[Namespace]_[Module]</module>
                    <frontName>[module]</frontName>
                </args>
            </[module]>
        </routers>
        <layout>
            <updates>
                <[module]>
                    <file>[module].xml</file>
                </[module]>
            </updates>
        </layout>
    </frontend>   
    <global>
        <models>
            <[module]>
                <class>[Namespace]_[Module]_Model</class>
                <resourceModel>[module]_mysql4</resourceModel>
            </[module]>
            <[module]_mysql4>
                <class>[Namespace]_[Module]_Model_Mysql4</class>
                <entities>
                    <[module]>
                        <table>[module]</table>
                    </[module]>
                </entities>
            </[module]_mysql4>
        </models>
        <resources>
            <[module]_setup>
                <setup>
                    <module>[Namespace]_[Module]</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </[module]_setup>
            <[module]_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </[module]_write>
            <[module]_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </[module]_read>
        </resources>
        <blocks>
            <[module]>
                <class>[Namespace]_[Module]_Block</class>
            </[module]>
        </blocks>
        <helpers>
            <[module]>
                <class>[Namespace]_[Module]_Helper</class>
            </[module]>
        </helpers>
    </global>
</config>

X-debug installation and configuration

Find a few installation references

Few steps for having  x-debug working on your local environment or development:

  1. Download the proper xdebug extension http://xdebug.org/download.php, or you can use xdebug wizard http://xdebug.org/wizard.php for more information about the environment.
  2. An alternative is to install using pecl: pecl install xdebug
  3. Copy binary file to PHP’s extensions folder
  4. Link this binary file in php.ini using this command zend_extension=”/usr/local/php/modules/xdebug.so”
  5. Enable xdebug in php.ini and configure to listen remote connections
    xdebug.remote_enable=true
    xdebug.remote_port="<the port for XDebug to listen to>" (the default port is 9000)
    xdebug.remote_host=<the host where PhpStorm is running (e.g. localhost)>
    xdebug.remote_handler=dbgp 
    xdebug.remote_mode=req
    xdebug.idekey=PHPSTORM
    xdebug.profiler_enable=1
    xdebug.profiler_output_dir="<AMP home\tmp>"
  6. You can check if xdebug is configured properly in PHP info.

Performance fix for EAV module

This module is a performance fix for all community and enterprise versions before 1.9.

Since I worked for a store having very complex products (with a large number of attributes and large scale of values), I discovered that Magento has a performance bottleneck on the product listing page and product page.

By having a closer look at the class Mage_Eav_Model_Entity_Attribute_Source_Table you can observe that getOptionText method use

 $options = $this->getAllOptions(false);

which is getting all records from the database and then filter them like this:

  foreach ($options as $item) {
            if ($item['value'] == $value) {
                return $item['label'];
            }
        }

This module will be useful for Magento shops with products with a large number of attributes or/and a large scale of values.

Download the module here https://github.com/georgebabarus/mage-eav-option-performance-fix

Simple carousel for Magento e-commerce

Purchase this extension for 75$ here  http://shop.babarus.ro/simple-carousel-content-products-and-banners.html

Manage your content in a simple way is possible with BB Simple Content Carousel.

Check the video for more details and the demo listed below.

  • Magento 1.9.1

Fronted: http://slider.mage19.demo.babarus.ro
Admin: http://mage19.demo.babarus.ro/index.php/admin
User: bb_slider
Password: bb_slider123

  • Magento 1.8.1

Fronted: http://slider.mage18.demo.babarus.ro
Admin: http://mage18.demo.babarus.ro/index.php/admin
User: bb_slider
Password: bb_slider123

Video tutorials