Categories


Archives


Recent Posts


Categories


One Line Observers

astorm

Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

I’ve started creating single line observers like this

<?php
class Mycompany_Mymodule_Model_Observer
{
    public function someMethod($observer)
    {
        Mage::helper('mycompany_mymodule/observer')
        ->someMethod($observer->getCustomer());
    }
}

The logic is punted to a helper class. This way the helper receives only the objects it needs (in the example above, customer), and can be tested/developed in isolation from the actual event.

So far it’s working a heck-of-a-lot-better than the selenium tests I used when writing checkout event observers.

Copyright © Alana Storm 1975 – 2023 All Rights Reserved

Originally Posted: 27th June 2011

email hidden; JavaScript is required