Websites, Stores, Store Views

Here is what can be set at each level:

Default Web Site Store Store View
Product attributes X X
Product prices X X
Product tax class X X
Base currency X X
(Default) display currency X X
Category settings X X
System configuration settings X X X
Root category configuration X
Orders X
Customer sharing X X

Thanks to F...

View Status of EE Mview Changelog Tables

This SQL:

select emm.view_name,
    emm.status,
    emm.version_id as metadata_version,
    cl_max_versions.max_version as cl_version,
    (cl_max_versions.max_version - emm.version_id) as behind
from enterprise_mview_metadata emm
left join (
    select 'enterprise_url_rewrite_redirect' as view_name, max(version_id) as max_version from enterprise_url_rewrite_redirect_cl union
    select 'cataloginventory_stock_status_view' as view_name, max(version_id) as max_version from cataloginventory_stock_status_cl union
    select 'enterprise_url...

Security problem: {block} has not been whitelisted

This is introduced by either SUPEE-6788, or Magento 1.9.2.2. See the link.

XMLRPC API

The XMLRPC API parameters always confuse me, they're below:

Login:

<?xml version="1.0"?>
<methodCall>
  <methodName>login</methodName>
  <params>
    <param>
        <value><string>zapier</string></value>
    </param>
    <param>
        <value><string>monkey</string></value>
    </param>
  </params>
</methodCall>

Order list:

<?xml version="1.0"?>
<methodCall>
  <methodName>call</methodName>
  <params>
    <param>
        <value>
            <string>884e467da9850...

Creating a Datetime attribute that stores time

Magento has a Datetime backend model but formats a Zend_Date object without the time. So if you want to store datetime (actually with time) you will need to setup your own backend model.

Here is how i've done it:

class Namespace_Module_Model_Entity_Attribute_Backend_Datetime extends Mage_Eav_Model_Entity_Attribute_Backend_Datetime
{
    const DATETIME_DATEPICKER_FORMAT = 'd/m/Y H:i';

    /**
     * Prepare date for save in DB
     *
     * @param   string | int $date
     * @return  string
     */
    public function formatDate($dat...

Admin Grids - Filtering A Joined Column

Often, you'll want to add a column to a collection used in a grid, and to do so you'd use _prepareCollection():

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $this->setCollection($collection);

    $collection->getSelect()
       ->joinLeft(
           array('table_alias' => 'some_long_table_name'),
           'main_table.something = table_alias.something',
           array('some_column' => 'table_alias.some_column')
       );

...

Adding A Column to a Flat Table

Handy to add attributes to sales_flat_order:

$installer->getConnection()->addColumn(
    $this->getTable('sales/order'),
    'some_attribute',
    [
        'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
        'length' => 1,
        'comment'=> 'Comment'
    ]
);

UK Tax / VAT Setup Script

This script sets up everything for UK VAT from a default 1.9.1.0 install.

<?php
/* @var $installer Mage_Core_Model_Resource_Setup */
$installer = $this;
$installer->startSetup();

/**
 * Define VAT band names
 */
define('VAT_STANDARD', 'VAT Standard');
define('VAT_REDUCED', 'VAT Reduced');
define('VAT_ZERO', 'VAT Zero');

/**
 * Remove current rules, rates and product classes
 */
$taxCalculation = Mage::getModel('tax/calculation');
foreach (Mage::getModel('tax/calculation_rule')->g...

Generate Test Products

I took this script from somewhere (sorry I forgot where!) but it didn't work for 1.9.1.0, so I fixed it up. Really basic, but useful, I used it to test pagination:

<?php
require 'app/Mage.php';
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
for ($i = 0; $i < 100; $i++) {
    Mage::getModel('catalog/product')
        ->setWebsiteIds(array(1))
        ->setAttributeSetId(4)
        ->setTypeId('simple')
        ->setSku($i)
        ->setStatus(1)
        ->setTaxClassId(2)
  ...

Get Value of Product Attribute

This resolves the value of the attribute, so rather than supplying you with a value ID, it will supply you with the associated value, via the source model:

$_product->getAttributeText('brand');

Non-Required Category Attribute Not Set in Global Scope

When a category is created whilst in a store scope, and a value is set against an attribute which has is_required set to false, and has a scope more specific than global, then a value is not set against the global scope, resulting in the store scope having a value, but the global scope having no value. This also has the effect of causing the flat category table for the store in question to have a null value for the attribute, even in the store scope that it is set in.

On this install, the attribute in question is display_as_link:

!...

Get Methods of Class

Yes, very dirty, but it works a treat! Save this file in your Magento root directory, then fire up a command line and run whatever.php Mage_Core_Model_App (or some other class) and you should see the output.

Output looks like below:

$ ./classmethods.php Varien_Db_Adapter_Pdo_Mysql
__construct                      Zend_Db_Adapter_Abstract      lib/Zend/Db/Adapter/Abstract.php:43
__destruct                       Varien_Db_Adapter_Pdo_Mysql   lib/Varien/Db/Adapter/Pdo/Mysql.php:30
__sleep                          Zend_Db_Ada...

Getting the Theme In Use

How to get the theme for each component, works on the active store:

Mage::getSingleton('core/design_package')->getTheme('locale');
Mage::getSingleton('core/design_package')->getTheme('template');
Mage::getSingleton('core/design_package')->getTheme('skin');
Mage::getSingleton('core/design_package')->getTheme('layout');
Mage::getSingleton('core/design_package')->getTheme('default');

Layout Loading and Misc Notes

Layout XML files are loaded here via this stack - here we are loading the layout update for the rwd/default design package, for the CMS home page. I've put a dashed line on the demarcation between layout code and other code:

Mage_Core_Model_App->run(Array)
Mage_Core_Controller_Varien_Front->dispatch()
Mage_Core_Controller_Varien_Router_Standard->match(Mage_Core_Controller_Request_Http)
Mage_Core_Controller_Varien_Action->dispatch('index')
Mage_Cms_IndexController->indexAction()
Mage_Cms_Helper_Page->renderPage(Mage_C...

Magento PHP & HTTPD Timeouts

nginx

fastcgi_read_timeout

php-fpm

request_terminate_timeout

php:

max_execution_time

varnish:

.first_byte_timeout
.between_bytes_timeout

Resetting File & Folder Permissions

You might want to do this on media or elsewhere, handy cut-and-paste job:

find . -type d -exec chmod 0755 {} \;
find . -type f -exec chmod 0644 {} \;

Or with an xargs version (which should be faster):

find media -type d -print0 | xargs -0 chmod 0755
find media -type f -print0 | xargs -0 chmod 0644

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