Magento Version History

Here is a table showing major changes over the Magento version history:

| CE | PE | EE | Year | Major Changes |
|-----|------|------|------|---------------------------------------------------------------------------------------------------------------------------------...

Nginx Virtual Store Subdirectories

Note - this article only applies to nginx and PHP-FPM!

If you want to have stores which are accessed via subdirectories as opposed to domain names, the standard method I've found is to make a directory with a copy of index.php in it, using one of the following approaches:

  • Leaving index.php exactly as-is, and calling fastcgi_param MAGE_RUN_CODE us; in your nginx config
  • Changing index.php to call a hardcoded string of us, either by altering the call to Mage::run(), or by setting $mageRunCode

I'm not happy with either o...

Varnish Cache Clears

Clear for an entire domain:

varnishadm "ban req.http.host == www.mydomain.com"

Clear for a URL on a domain that starts with something, or ends with something (just regex, so change as you like):

varnishadm "ban req.http.host == www.mydomain.com && req.url ~ ^/some-directory"
varnishadm "ban req.http.host == www.mydomain.com && req.url ~ .css$"

Clear for a specific URL:

varnishadm "ban req.http.host == www.mydomain.com && req.url == /some/specific/url"

Here is a nice cheatsheet for ya - [http://kly.no/varnish/regex.txt](...

Get All Children Of A Block

Sorted:

$this->getSortedChildren()

Unsorted:

$this->getChild()

Children of Anonymous Blocks are Orphaned

What a sad state of affairs. If a childs parent has no name, the child block becomes orphaned and alone, somewhere lost in Layout XML hell. To sort it, give the parent a name. The reason? The layout XML parser uses the name of the parent in XML to set the parent of the child block class instance, so if there is no name, the child is orphaned.

This won't work:

<block type="core/text_list">
    <block type="core/template" template="a/valid/template.phtml" />
</block>

This will:

<block type="core/text_list" name="whatever_th...

Stock Availability on Credit Note, Cancellation and Payment Deny

In summary - making a credit memo can increase the stock quantity but will never set the "Stock Availability" of the product to "In Stock", whereas a config option can control whether an order cancellation sets "In Stock" automatically. Denying a payment has the same behaviour as cancelling an order. If you want everything to have the same behaviour, set the config option to not set items status to be in stock on order cancellation.

Credit Memo

When crediting a credit memo, if you choose the "Return to Stock" option, this will only inc...

local.xml Boilerplate

For when you have no local.xml:

<?xml version="1.0"?>
<!--
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@m...

Import and URL Keys

Don't bother setting the url key, as this can be a tedious task in Excel, just simply import without one and reindex.

Removing Custom Attributes Across Multiple Products

If you have custom attributes named the same across multiple products, you
wish to remove said attributes, this might come in useful. The SQL below restricts
the removal of the attributes to a certain attribute set name, but you can remove
this is you want to remove custom options from all attribute sets:

DELETE o
FROM catalog_product_option o
INNER JOIN catalog_product_option_title t ON o.option_id = t.option_id
INNER JOIN catalog_product_entity p ON o.product_id = p.entity_id
INNER JOIN eav_attribute_set a ON p.attribu...

Creating a New Attribute Set Programatically

$entityTypeId = Mage::getModel('catalog/product')
                  ->getResource()
                  ->getEntityType()
                  ->getId();

$attributeSet = Mage::getModel('eav/entity_attribute_set')
                  ->setEntityTypeId($entityTypeId)
                  ->setAttributeSetName('test_set');

$attributeSet->validate();
$attributeSet->save();

$attributeSet->initFromSkeleton($skeletonID)->save();

You need to save before you do initFromSekeleton().

![](http://mikewhitby.co.uk/maka...

Limiting The Number of Autocomplete Results

SweetTooth details how to limit the number of autocomplete entries, as by default this list is not limited whatsoever, not good on a store with lots of products!

Associating An Orphan Sage Pay Suite Transaction With An Order

We had a situation whereby a client placed an order and went through Sage Pay
succesfully, however the order was not able to be created on Magento, so we had
an error stating "WARNING - There are approved Sage Pay transactions that have
no associated Magento orders. Click here to go to Orphan Transactions List".
This isn't the easiest of problems to solve, so here is how we did it:

  1. Find out the order details, this will probably mean ringing the customer and
    finding out what they ordered and where they want it delivered to.
    Alternat...

Windows Apache 2.4 VirtualHost Definition

Put this in your httpd.conf:

<VirtualHost *:80>
    DocumentRoot "C:/your/docroot"
    ServerName yourname.local
    DirectoryIndex index.php
</VirtualHost>
<Directory "C:/your/docroot">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Add Category Attributes Through SQL Updates

This is creating a module which will update categories to include new attributes.

  1. inside app/etc/modules/yourmodule.xml put the following:

     <?xml version="1.0"?>
     <config>
         <modules>
             <Yourmodule_Sql>
                 <active>true</active>
                 <codePool>local</codePool>
             <Yourmodule_Sql>
         </modules>
     </config>
    
  2. Next, inside app/code/local/Yourmodule/Sql/etc/config.xml put the following:

     <?xml version="1.0"?>
     <config>
    ...
    

Controller rewrite

Controller file:

<?php
/**
  * Controllers are not loaded with autoloader,
  * to extend a controller class we need to first call the actual class file
  * ExtendableController is that class fileName!
  */
require_once Mage::getBaseDir('code') . '/core/Mage/ModuleName/controllers/ExtendableController.php';

class Namespace_Module_SomeController extends Mage_ModuleName_ExtendableController
{
/**
 * your controller actions here
 */
}

Config:
see link

![](http://mikewhitby.co.uk/makandra-tr...

URL rewrite XML

The following remaps services/view/index/url_key/param:

<global>
    <rewrite>
        <service>
            <from><![CDATA[#^/services/(.+)#]]></from>
            <to><![CDATA[services/view/index/url_key/$1/]]></to>
            <complete>1</complete>
        </service>
    </rewrite>
</global>

Complete tag:
if set to 1 magento will use the source layout handles otherwise it will use new layout handles associated with the rewrite.

Getting The Amount Of Items in the Cart

To get the amount of line items (i.e. 10 of 1 product is 1):

Mage::helper('checkout/cart')->getItemsCount();

To get the total number of items (i.e. 10 of 1 product is 10):

Mage::helper('checkout/cart')->getSummaryCount();

Resize A Product Image

Mage::helper('catalog/image')->init($product, 'image')->resize(150);

Adding Attribute To Category List Product Collection

Only a core set of attributes are added to the product collection (for the list page) by default. This bit of XML will allow you to add additional attributes to that collection:

<config>
    <frontend>
        <product>
            <collection>
                <attributes>
                    <some_attribute/>
                </attributes>
            </collection>
        </product>
    </frontend>
</config>

![](http://mikewhitby.co.uk/makandra-track.gif?a=adding-attribute-to-category-list-produ...

Create Admin User/Role via SQL

Fasntastic webpage which allows you to create a new admin user and role via SQL - it does all the SQL generation for you and also looks lovely!

Find Unused Product Attributes

Just to keep things tidy!

SELECT attribute_id, attribute_code, frontend_label
FROM eav_attribute
WHERE entity_type_id = 4
AND attribute_id NOT IN(SELECT attribute_id FROM eav_entity_attribute);

Product EAV Attribute Set, Group and Attribute List

To see a list of all attribute sets, groups, and associated attributes for products, use this SQL. BONUS! Also shows the sort ordering, useful for determining which sort_order you need to place an attribute in a certain position:

SELECT s.attribute_set_name,
       g.attribute_group_name,
       a.attribute_code,
       a.frontend_label,
       ea.sort_order
FROM eav_attribute_set s
LEFT JOIN eav_attribute_group g   ON s.attribute_set_id   = g.attribute_set_id
LEFT JOIN eav_entity_attribute ea ON g.attr...