Recent Posts


One Line Observers


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

class Mycompany_Mymodule_Model_Observer
    public function someMethod($observer)

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 © Alan Storm 1975 – 2021 All Rights Reserved

Originally Posted: 27th June 2011