161 cards

Restoring console.log

To do this permanently by altering your JS files, comment out this code on line 637 of js/varien/js/js:

if (!("console" in window) || !("firebug" in console))
{
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {};
    for (var i = 0; i < names.length; ++i)
        window.console[names[i]] = function() {}
}

Or, you could paste this into your layout somewhere (...

Product Types

Type Composite[^1] Inventory[^2] Description Example
Simple - Yes The most basic form of product Example Archive
Grouped Yes No Several simple products displayed together, customer selection determines one or more simple products to be added to the basket, which are shown in the basket as seperate products Example Archive
Configurable Yes No Allows choosing of options which determin...

Sending Transactional E-Mails

$email = Mage::getModel('core/email_template');

$email->sendTransactional(
    'some_email_template',                                                 // template
    array('name' => 'Your Company', 'email' => 'contact@yourcompany.com'), // sender details
    'joe@joebloggs.com',                                                   // recipient email
    'Joe Bloggs',                                                          // recipient name
    array('customerName' => 'Joe Bloggs'),                                 /...
Draft

Various Link Types

Todo - this card should detail where links can be generated from (Mage, Mage_Core_Model_Store) and which methods generate them, and differentiate between web, link, direct link, skin, js and media links

Draft

Setting And Getting Cookies

To set cookies:
Mage::getModel('core/cookie')->set('cookie_name', 'cookie_value', 0); # session cookie
Mage::getModel('core/cookie')->set('cookie_name', 'cookie_value', 60); #lasts 60 seconds

To get cookies:
Mage::getModel('core/cookie')->get('made_productalerts_stock');

Linked content

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

Linked content

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.

Linked content

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>

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