161 cards

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>

Config Event Observer Definition (Frontend, Admin & Global)

Frontend:

<config>
    <frontend>
        <events>
            <the_name_of_the_event_to_observe>
                <observers>
                    <namespace_module>
                        <class>namespace_module/observer</class>
                        <method>someMethod</method>
                    </namespace_module>
                </observers>
            </the_name_of_the_event_to_observe>
        </events>
    </frontend>
</config>

Admin:


...

Config Block Definition

<config>
    <global>
        <blocks>
            <namespace_module>
                <class>Namespace_Module_Block</class>
            </namespace_module>
        </blocks>
    </global>
</config>

Config Setup Definition (EAV & Flat)

EAV:

<config>
    <global>
        <resources>
            <namespace_module_setup>
                <setup>
                    <module>Namespace_Module</module>
                    <class>Mage_Eav_Model_Entity_Setup</class>
                </setup>
            </namespace_module_setup>
        </resources>
    </global>
</config>

Flat:

<config>
    <global>
        <resources>
            <namespace_module_setup>
                <setup>
                    <module>Na...

Config Model & Resource Model Definition

<config>
    <global>
        <models>
            <namespace_module>
                <class>Namespace_Module_Model</class>
                <resourceModel>namespace_module_resource</resourceModel>
            </namespace_module>
            <namespace_module_resource>
                <class>Namespace_Module_Model_Resource</class>
                <entities>
                    <some_entity>
                        <table>namespace_module_some_entity</table>
                    </some_entity>...

Table Creation In Magento 1.6/1.11+

Magento CE 1.6 and PE/EE 1.11 introduced database abstraction, this is the way to set up tables using the new code.

$table = $installer->getConnection()
    ->newTable($installer->getTable('your_module/table_name_in_xml'))
    ->addColumn(
        'entity_id',
        Varien_Db_Ddl_Table::TYPE_INTEGER,
        null,
        array(
            'identity' => true,
            'unsigned' => true,
            'nullable' => false,
            'primary'  => true,
        ),
        'Entity ...

Resizing via Varien_Image

$image = new Varien_Image('/full/fs/path/to/image.jpg');

// you cannot use method chaining with Varien_Image
$image->constrainOnly(false);
$image->keepFrame(true);
// avoid black borders by setting background colour
$image->backgroundColor(array(255,255,255));
$image->keepAspectRatio(true);
$image->resize(216, 139);
$image->save('/full/fs/path/to/save/to.jpg');

This website uses short-lived cookies to improve usability.
Accept or learn more