161 cards

Config Block rewrite Definition

<config>
    <global>
        <blocks>
            <catalog>
                <rewrite>
                    <product>Namespace_Module_Block_Catalog_Product</product>
                </rewrite>
            </catalog>
        </blocks>
    </global>
</config>

Helper Block Definition

<config>
    <global>
        <helpers>
            <namespace_module>
                <class>Namespace_Module_Helper</class>
            </namespace_module>
        </helpers>
    </global>
</config>

Pretty Debug Output

Yeh it's not Magento, but this might help some people:

Zend_Debug::dump()

Basically it's var_dump but with <pre> tags, no biggie but it's nice to use.

Return Store Variables (Phone Number, Address, E-Mail etc)

Name:

Mage::getStoreConfig('general/store_information/name')

Phone number:

Mage::getStoreConfig('general/store_information/phone')

Address:

Mage::getStoreConfig('general/store_information/address')

E-Mail:

Mage::getStoreConfig('trans_email/ident_general/email')

Get Category Children

public function getCategories() 
{
    if (!$this->categories) {
        $categoryId = $this->getData('parent_category_id');
        $parentCategory = Mage::getModel('catalog/category')->load($categoryId);

        $categoryCollection = $parentCategory->getCollection();
        $categoryCollection->addAttributeToSelect('url_key')
            ->addAttributeToSelect('name')
            ->addAttributeToSelect('image')
            ->addAttributeToFilter('is_active', 1)
            ->addAttributeToFilte...

Get and Resize Category Images

public function getCategoryImage(Mage_Catalog_Model_Category $category, $width = 250, $height = 250)
{
    // return when no image exists
    if (!$category->getImage()) {
        return false;
    }

    // return when the original image doesn't exist
    $imagePath = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category'
               . DS . $category->getImage();
    if (!file_exists($imagePath)) {
        return false;
    }

    // resize the image if needed
    $rszImagePat...

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

/**
 * 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/lice...

Boilerplate Resource Model Class (Before CE 1.6 / EE 1.11)

/**
 * 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 You...
Linked content

Admin - Creating A Basic Grid And Edit Form

Much easier to show how this is done by showing you some code examples, so please see the link attached.

Linked content

Admin Form Field Types

The various types are:

  • text
  • textarea
  • multiline
  • select
  • multiselect
  • radio
  • checkbox
  • password
  • time
  • note
  • label
  • link
  • image
  • file
  • date
  • submit

See the link for detailed usage information

Linked content

Translating Javascript Strings

Use this syntax:

Translator.translate('Some phrase');

I believe you also have to make the translation available to the Translate class in this manner:

<script type="text/javascript">
Translator.add('You should take care of this confirmation message!','<?php echo Mage::helper('yourmodule')->__('You should take care of this confirmation message!')?>');
</script>

Fetching All Attributes For An Entity From The DB In One Query

Using the database to inspect EAV-based entity types can be a real pain in the ass, so here are a bunch of queries that let you inspect some popular EAV entity types easily. This practice can be applied to any EAV entity type, however as there are about 25 of them, I decided to just list the popular ones, enjoy.

Output example (shortened):

|----------------------------------+----------+----------+---------------------|
| attribute_code | type | store_id | value |
|----------------------------------+-----...

Add All Attributes To A Collection

$attributes = Mage::getSingleton('catalog/config')->getProductAttributes();
$collection->addAttributeToSelect($attributes);

Add A Tab To The Admin Product Screen

Declare an admin layout XML file for your module in your config.xml:

<config>
    <adminhtml>
        <layout>
            <updates>
                <your_module>
                    <file>your-module.xml</file>
                </your_module>
            </updates>
        </layout>
    </adminhtml>
</config>

Create the layout XML in /app/design/adminhtml/default/default/layout/your-module.xml:

<?xml version="1.0"?>
<layout>
    <adminhtml_catalog_product_edit>
        <refer...

Add A Tab To The Admin Product Screen

Adding A Tab To The Product Screen

  1. Declare an admin layout XML file for your module in your config.xml:

  2. Create the layout XML in /app/design/adminhtml/default/default/layout/your-module.xml:

Linked content

Magento Multi Database Guide

Handy link to a very useful PDF which details how to handle multiple databases in Magento.

Linked content

Raw Database Queries

The attached link describes everything fantastically, just go there.

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