Database Schema

This site shows details of the Magento database schema for differing versions - it shows foreign key relationships in a nice drag-and-drop interface

Event List

This page has a listing of all the Magento events - it has been extracted by grepping the source so may not be entirely complete.

Using Design Exceptions To Serve a Mobile Theme

In order to serve a different package, or any element of a theme (translations, templates, skin or layout) you can use design exceptions, which allow you to specify different values for each of the design-related settings by using user-agent string matches

In Stock Product Collection

This snippet provides a collection of in-stock products, or products which do not have stock management enabled on them

$productCollection = Mage::getResourceModel('catalog/product_collection');
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection);

Magento Model Diagram

This is a high-level view of the Magento Model, Resource Model and Resource Collection Model structure

Cause FPC To Cache A Route

<config>
    <frontend>
        <cache>
            <requests>
                <frontname>
                    <controller>
                        <action>enterprise_pagecache/processor_category</action>
                    </controller>
                </frontname>
            </requests>
        </cache>
    </frontend>
</config>

Adding Breadcrumbs

Via code (usually in a controller):

$crumbs = Mage::app()->getLayout->getBlock('breadcrumbs');
$crumbs->addCrumb('home', array(
    'label' => 'Home',
    'title' => 'Go to Home Page',
    'link' => Mage::getUrl('')
));

Via Layout XML:

<reference name="breadcrumbs">
    <action method="addCrumb">
        <crumbname>Home</crumbname>
        <crumbinfo>
            <label>Home</label>
            <title>Go to Home Page</title>
            <link>/</link>
        </crumbinfo>
    </a...

Getting A Database Adapter (Read or Write)

To read:

Mage::getSingleton('core/resource')->getConnection('core_read');

To write:

Mage::getSingleton('core/resource')->getConnection('core_write');

Product Attribute Addition

This code shows all possible configuration options for an attribute that I know of, you need not include all of these when adding an attribute (although it won't hurt)

$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');

if (!$installer->getAttributeId(Mage_Catalog_Model_Product::ENTITY, 'attribute_name')) {
    $installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'attribute_name', array(         // TABLE.COLUMN:                                       DESCRIPTION:
        'label'                    ...

Enabling MySQL Query Logging

In /lib/Varien/Db/Adapter/Pdo/Mysql.php change this property to true:

/**
 * Write SQL debug data to file
 *
 * @var bool
 */
protected $_debug               = false;

To enable logging for queries slower than a certain time, alter this property:

/**
 * Minimum query duration time to be logged
 *
 * @var float
 */
protected $_logQueryTime        = 0.05;

To log all queries, set this property to true:

/**
 * Log all queries (ignored minimum query duration time)
 *
 * @var bool...

Enabling The Profiler

In index.php uncomment this line:
#Varien_Profiler::enable();

In the admin enable the profiler output:

Set System > Configuration > Advanced > Developer > Debug > Profiler to yes

To enable the Zend_Db profiler add the following node to your app/etc/local.xml file. It can be added into your database connection configuration. The output will also be displayed if the admin setting above is set to true.

<global>
    <resources>
        <default_setup>
            <connection>
                <profiler>tr...

Boilerplate Admin Controller

/**
 * Yourcompany.com
 *
 * PHP Version 5
 *
 * @category  Namespace
 * @package   Namespace_Module
 * @author    Your Name <your.name@yourcompany.com>
 * @copyright 2012 yourcompany.com
 * @license   http://www.yourcompany.com/license.txt Your license
 * @link      N/A
 */

/**
 * A description of the controller
 *
 * @category Namespace
 * @package  Namespace_Module
 * @author   Your Name <your.name@yourcompany.com>
 * @license  http://www.yourcompany.com/lice...

Converting A Quote Attribute To An Order

<config>
    <global>
        <fieldsets>
            <sales_convert_quote>
                <some_attribute>
                    <to_order>*</to_order>
                </some_attribute>
            </sales_convert_quote>
        </fieldsets>
    </global>
</config>

Using Differing Setup Classes In One Module

On occasion you may have a module which requires both EAV and flat resource setup classes, in this situation you can instantiate a setup class as this note shows.

Eav:

$installer = Mage::getModel('eav/entity_setup', 'eav_setup');

Flat:

$installer = Mage::getResourceModel('core/setup', 'core_setup');

Catalog:

$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');

You can then continue with the setup script as you normally would.

![](http://mikewhitby.co.uk/makandra-track.gif?a=using-differing-setup-classes-...

Boilerplate FPC No-Cache Container

This container, when combined with a Placeholder Definition will cause the referenced block to never be cached.

/**
 * Yourcompany.com
 *
 * PHP Version 5
 *
 * @category  Namespace
 * @package   Namespace_Module
 * @author    Your Name <your.name@yourcompany.com>
 * @copyright 2012 yourcompany.com
 * @license   http://www.yourcompany.com/license.txt Your license
 * @link      N/A
 */

/**
 * Cache containe...

Config FPC Placeholder Definition

This should go in cache.xml. See Boilerplate FPC No-Cache Container for a boilerplate container.

<config>
    <placeholders>
        <namespace_module>
            <block>namespace_module/something</block>
            <placeholder>NAMESPACE_MODULE_UNIQUE_STRING</placeholder>
            <container>Namespace_Module_Model_Pagecache_Container</container>
            <cache_lifetime>86400</cache_lifetime> <!-- never gets used -->
     ...

Boilerplate Resource Model Collection Class (CE 1.6 / EE 1.11 And After)

/**
 * Yourcompany.com
 *
 * PHP Version 5
 *
 * @category  Namespace
 * @package   Namespace_Module
 * @author    Your Name <your.name@yourcompany.com>
 * @copyright 2012 yourcompany.com
 * @license   http://www.yourcompany.com/license.txt Your license
 * @link      N/A
 */

/**
 * Something resource collection model
 *
 * @category Namespace
 * @package  Namespace_Module
 * @author   Your Name <your.name@yourcompany.com>
 * @license  http://www.yourcompany.com/...

Boilerplate Resource Model Class (CE 1.6 / EE 1.11 And After)

/**
 * Yourcompany.com
 *
 * PHP Version 5
 *
 * @category  Namespace
 * @package   Namespace_Module
 * @author    Your Name <your.name@yourcompany.com>
 * @copyright 2012 yourcompany.com
 * @license   http://www.yourcompany.com/license.txt Your license
 * @link      N/A
 */

/**
 * Something resource model
 *
 * @category Namespace
 * @package  Namespace_Module
 * @author   Your Name <your.name@yourcompany.com>
 * @license  http://www.yourcompany.com/license.txt...

Boilerplate Model Class

/**
 * Yourcompany.com
 *
 * PHP Version 5
 *
 * @category  Namespace
 * @package   Namespace_Module
 * @author    Your Name <your.name@yourcompany.com>
 * @copyright 2012 yourcompany.com
 * @license   http://www.yourcompany.com/license.txt Your license
 * @link      N/A
 */

/**
 * Something model
 *
 * @category Namespace
 * @package  Namespace_Module
 * @author   Your Name <your.name@yourcompany.com>
 * @license  http://www.yourcompany.com/license.txt Your lic...

Boilerplate Helper Class

/**
 * Yourcompany.com
 *
 * PHP Version 5
 *
 * @category  Namespace
 * @package   Namespace_Module
 * @author    Your Name <your.name@yourcompany.com>
 * @copyright 2012 yourcompany.com
 * @license   http://www.yourcompany.com/license.txt Your license
 * @link      N/A
 */

/**
 * Module translation helper
 *
 * @category Namespace
 * @package  Namespace_Module
 * @author   Your Name <your.name@yourcompany.com>
 * @license  http://www.yourcompany.com/license.tx...

Boilerplate Block Class

With template support:

/**
 * Yourcompany.com
 *
 * PHP Version 5
 *
 * @category  Namespace
 * @package   Namespace_Module
 * @author    Your Name <your.name@yourcompany.com>
 * @copyright 2012 yourcompany.com
 * @license   http://www.yourcompany.com/license.txt Your license
 * @link      N/A
 */

/**
 * Something block
 *
 * @category Namespace
 * @package  Namespace_Module
 * @author   Your Name <your.name@yourcompany.com>
 * @license  http://www.yourcompany....

Config Controller Definition (Frontend & Admin)

Frontend With Route:

<config>
    <frontend>
        <routers>
            <namespace_module>
                <use>standard</use>
                <args>
                    <module>Namespace_Module</module>
                    <frontName>whatever</frontName> <!-- http://dev.local/whatever/*/* -->
                </args>
            </namespace_module>
        </routers>
    </frontend>
</config>

Frontend Injected (Sales given as an example):

<config>
    <frontend>
        <r...

Config Layout Definition (Frontend & Admin)

Frontend:

<config>
    <frontend>
        <layout>
            <updates>
                <namespace_module>
                    <file>namespace-module.xml</file>
                </namespace_module>
            </updates>
        </layout>
    </frontend>
</config>

Admin:

<config>
    <adminhtml>
        <layout>
            <updates>
                <namespace_module>
                    <file>namespace-module.xml</file>
                </namespace_module>
       ...

Config Cronjob Definition

<config>
    <crontab>
        <jobs>
            <cron_job_name>
                <schedule>
                    <cron_expr>* * * * *</cron_expr>
                </schedule>                
                <run>
                    <model>your_module/model::batchTransactions</model>
                </run>
            </cron_job_name>
        </jobs>
    </crontab>
</config>