161 cards

Custom Cache Type Definition

Adding this XML will cause an additional entry to appear in the Magento Cache Management screen.

             <your_cache_type module="your_module" translate="label description">
                <label>Your Custom Cache Label</label>
                <description>Description of cache type.</description>


Messages and Global Messages Blocks

Both use the same block, as we can see in page.xml:

<block type="core/messages" name="global_messages" as="global_messages"/>
<block type="core/messages" name="messages" as="messages"/>

When you add a message, you add it to the session, rather than to either of the
messages blocks, so the code below causes the Mage_Customer_Model_Session object
to have an error logged to it:

Mage::getSingleton('customer/session')->addError('Please enter all required information');

At this point neither message blocks know anything about the...

Reindex Via Code

An example of code qhich allows you to reindex:

$indexer = Mage::getSingleton('index/indexer');
$process = $indexer->getProcessByCode('catalog_product_price');

The following are indexer codes which you can use instead of the catalog_product_price
index above:

catalog_product_attribute     Product Attributes
catalog_product_price         Product Prices
catalog_url                   Catalog URL Rewrites
catalog_product_flat          Product Flat Data
catalog_category_flat     ...

Getting The Last Order ID From The Session



Widget Parameter ID Weirdness

I've not yet found out why, but this will not work:

    <some_widget type="some_module/block" translate="name description" module="some_module">
            <script_tag_id translate="label description">
                <label>Script Tag ID</label>
                <description>The ID for the script tag, this looks like DoubleClickF...
Linked content

Adding A CSS Class To The Body Tag

To add a class via layout XML:

<reference name="root">
    <action method="addBodyClass"><classname>whatever</classname></action>

Or to add via code, from a controller or block

if ($root = $this->getLayout()->getBlock('root')) {

EAV Tables

A list of EAV tables and their purpose.

| Table | Contains |
| eav_attribute | Attributes and their global config values |
| catalog_eav_attribute | Catalog...

Import Resetting visibility and stock attributes

If you are updating an existing product you need to include the stock and visibility attributes, otherwise the stock for the product will get set to 0 and out of stock, and the visibility will be reset to Catalog, Search.

Allowing Import Of Invisible Attributes

By setting a Product Attribute to be invisible via the visible property, you stop the ability to import that attribute unless you alter the _forcedAttributesCodes property of the relevant product type. The class names are:

  • Mage_ImportExport_Model_Import_Entity_Product_Type_Simple
  • Mage_ImportExport_Model_Import_Entity_Product_Type_Grouped
  • Mage_ImportExport_Model_Import_Entity_Product_Type_Configurable

The best method is probably to subclass the relevant pro...

Linked content

Custom Admin Grid Column Renderer

When you need to display an image in a column, or format a value in a particular way, you can use a custom renderer to present the data differently.

Linked content

Custom EAV Frontend Input Renderer

Handy for adding an attribute to a product or category which needs a custom frontend input type.

Image Resize Helper Composition

The product image resizing goes through a few layers of abstraction, so I thought I'd add a quick UML diagram showing composition through the layers. The resizing ultimately gets done by the gd PHP extension.

startSetup() and endSetup()

Ever wondered what they do? Basically they disable and then enable foreign key checks, and set the SQL mode to NO_AUTO_VALUE_ON_ZERO, then back to the old SQL mode. Below is the code taken from Varien_Db_Adapter_Pdo_Mysql:

 * Run additional environment before setup
 * @return Varien_Db_Adapter_Pdo_Mysql
public function startSetup()
    $this->raw_query("SET SQL_MODE=''");

Attribute Source Model

Used when you want to use a multiselect or select dropdown box on an EAV entity, such as products or categories.

class Namespace_Module_Model_Select extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
     * Retrieve Full Option values array
     * @param bool $withEmpty     Add empty option to array
     * @param bool $defaultValues
     * @return array
    public function getAllOptions($withEmpty = true)
        if (!$this->_options) {

Javascript Cookie Functions

This doesn't really go here, but hey ho. Magento's functions in js/Mage/cookies.js are not very good.

 * Get a cookie value
 * @param String name The cookie name
 * @return String The cookie value
getCookie: function(name)
    var val = '';
    var cookies = document.cookie.split('; ');
    for (i = 0; i < cookies.length; i++) {
        nameVal  = cookies[i].split('=');
        if (nameVal[0] == name) {
            val = unescape(nameVal[1]);

Changing The Admin Theme

Put this in your local.xml:


Fetching Store Contact E-Mail Addresses

// General Contact
$name =  Mage::getStoreConfig('trans_email/ident_general/name'); 
$email = Mage::getStoreConfig('trans_email/ident_general/email');

// Sales Representative
$name =  Mage::getStoreConfig('trans_email/ident_sales/name'); 
$email = Mage::getStoreConfig('trans_email/ident_sales/email');

// Customer Support
$name =  Mage::getStoreConfig('trans_email/ident_support/name'); 
$email = Mage::getStoreConfig('trans_email/ident_support/email');

// Custom Email 1
$name =  Mage::getStoreConf...
This website uses short-lived cookies to improve usability.
Accept or learn more