browse the blogs

[ 17 Jul 2014 ]

Configuration Gaslighting Checklist:

A quick Stack Overflow answer from yours truly that covers what to do when you think Magneto’s gaslighting you on configuration values you’re sure you’ve changed.

[ 16 Jul 2014 ]

I needed to grab a few category names when all I had were the category IDs

$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('name')
->addFieldToFilter('category_id', array('in'=>$product['category_ids']));

Can you spot the error? PHP complained with the following error

Fatal error: Call to a member function getBackend() on a non-object in /Users/alanstorm/Sites2014/magento-1-9-0-0.dev/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 816

Can you spot the error now? Unless you happen to be working on a project where you’re deep inside Magento’s EAV implementation, the above error message is worse than useless when it comes to tracking down the actual error.

The problem was I used category_id — and a Magento category object has no such field. I should have used entity_id. Easy brain fart — made easier in that Magento doesn’t stick to the …

[ 13 Jul 2014 ]

In a stock Magento system, there’s several tables where a row will have an ID field of 0.

mysql> select * from core_store\G:
*************************** 1. row ***************************
  store_id: 0
      code: admin
website_id: 0
  group_id: 0
      name: Admin
sort_order: 0
 is_active: 1
*************************** 2. row ***************************
  store_id: 1
      code: default
website_id: 1
  group_id: 1
      name: Default Store View
sort_order: 0
 is_active: 1

In turn, there are times where the Magento application will assume these 0 ID rows exist. For example, a store ID of 0 is always interpreted as the admin store object.

In day to day operations this is no big deal — however MySQL …

[ 7 Jul 2014 ]

If you’re new to Magento, you may not realize that every remote API method has a native PHP equivalent. The why, how, and how to identify these models is covered elsewhere, but one thing I forget at my peril is how useful the API methods are when I need to serialize something as JSON or via PHP’s serialize function.

json_encode(
    Mage::getModel('catalog/product')->load($product_id)
);

$data = serialize(Mage::getModel('catalog/product')->load($product_id));

What’s great about the API load methods is they automatically return a simple PHP array full of scaler values. Compare that to something like this

json_encode(    
    Mage::getModel('catalog/product')->load($product_id)
);

While they may seem equivalent, the catalog/product object is going to have a lot of other object references — which …

[ 5 Jul 2014 ]

Can’t Log into the Admin Roundup:

Stack Exchange answer where I (attempt to?) list every possible reason the Magento Admin might not set a session cookie, creating the dreaded “can’t log into the admin” error.

[ 5 Jul 2014 ]

Anti-SQL Bias:

Developers coming into Magento are often put off by seemingly voodoo rituals like “Don’t directly manipulate the database tables with SQL”. This may be a ritual, but it’s a smart one, and my answer to this questions tells you why. It also includes an example SQL query for fetching all the product status values when you’re ready to dive deep on Magento’s EAV structure.

[ 1 Jul 2014 ]

I can’t login to Magento Admin:

Another misconfiguration that can make it impossible for developers to log into the Magento admin.

[ 29 Jun 2014 ]

tim-reynolds/magento-qconfig:

When I started using Magento the System Configuration section made me feel a little dumb — so many options, but no easy way to search for things. I’d always forget where a particular option was.

After a few months of using grep and ack to search though the system.xml files and work backwards to figure out the section, I decided to automate that process and the System Configuration Search module was the result.

Tim Reynolds had the same idea, and created a similar module named qconfig. I’ve also seen a few other implementations floating around, but I really like what Tim’s done with the search visualizations. It makes me extra embarrassed about my goofy dancing arrows. …

[ 25 Jun 2014 ]

Magento system.xml hint tag. :

Some background on an abandoned “hint” tag for Magento’s system configuration form fields.

[ 19 Jun 2014 ]

Barely Magento related — mainly a tab sweep to capture some Stack Overflow questions where I’m re-familiarizing myself with DBA concepts as part of a Magento upgrade project.

Optimizing ALTER TABLE

Debugging errno: 150

More errno: 150