161 cards

Reloading Varnish Config Without a Restart

varnishadm
vcl.load reload01 /etc/varnish/default.vcl
vcl.use reload01

If you do more than one reload, you'll need to use reload02, reload03, etc.

Adding Attributes To Other Entities With getDefaultEntities()

Don't do it!! I did the below:

public function getDefaultEntities()
{
    return array(
        'catalog_product' => array(
            'attributes' => array(
                'size_guide_id' => array(
                    'group'                      => 'General',
                    'label'                      => 'Size Guide',
                    'type'                       => 'int',
                    'input'                      => 'select',
                    'source_model'               =>...

Many to Many Resource Model Mapping

This is some boilerplate code to facilitate the use of many-to-many relationship tables in Magento. I found myself rewriting this code often, so this saves some time. This example links a sizeguide entity to attribute sets. Obviously you'll need to make the entity table and the relationship table first, and you'll need to change the code to match your column names, but this gets you most of the way:

Resource Model - Loading and Saving

/**
 * Load the attribute set relations onto an object
 *
 * This is public as we need...

Creating an EAV Entity

Overview

A overview for those familiar with making flat models:

  • Your config is standard, your table name takes the form of the base (entity) table
  • You name your resource models as normal (so by class name, you can't tell the difference between flat and EAV)
  • You make your domain model as normal
  • Your resource model extends a different class and has different _construct() code
  • Your resource collection model extends a different class, but is otherwise the same
  • You make your entity and value tables using setup DDL as you would...

Show All Indexes On a DB

Again, not Magento. Very handy though!

SELECT DISTINCT
    TABLE_NAME,
    INDEX_NAME
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = 'your_schema';

Then you can use show indexes from table_name to see more info about the index.

Cross-Border Tax

This one was very confusing. Lets say you have two stores - one in the US, and one in Japan. You can obviously ship to Japan from the Japanese store (same with the US), but you can also ship to Japan from the US store, and vice versa.

You only have Retail Customer as a group (default), and you've got a list of product tax classes which are shared between the US and Japanese store. So off you go on your merry way setting up US and Japanese tax rates and rules to set the tax - great so far, US customers to the US sare charged correctly, same ...

Dataflow Per-Store Import Causing Copy of All Attributes

Fancy importing a subset of some product attributes on a per-store basis, whilst keeping the attributes that weren't imported using the defaults?

Tough, you can't!

Well, not with dataflow anyway. This card covers how Magento handles product saves, and the dataflow product adapter 'suffers' from this issue (by the way, the adapter class is Mage_Catalog_Model_Convert_Adapter_Product in case you fancy taking a look, the parse() method is where the magic happen...

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...
Draft

Cache

Here is a quick rundown of cache initialisation, from the group up.

Mage::run() or Mage::app()

    Mage_Core_Model_App::init() or Mage_Core_Model_App::baseInit()

        Mage_Core_Model_App::_initCache();

            Mage_Core_Model_Cache::__construct()

                use _getBackendOptions() and _getFrontendOptions() to sanitise options

                use Zend_Cache::factory() to get frontend and backend:

                    frontend: Varien_Cache_Core
                    backend: Zend_Cache_Backend...

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...
Linked content

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...

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