Hire Magento Developer - I am available now
22
Jun

It is worth to notice that Mage_Core_Model_Abstract class comes with special event properties: $_eventPrefix and $_eventObject. These values will be used when dispatching events on most common operations. For example, when saving an object into database, two events are dispatched – model_save_before and model_save_after. At the same time Magento dispatches two other events: $_eventPrefix . ‘_save_before’ and $_eventPrefix . ‘_save_after’. Dispatched events will contain model reference stored in $_eventObject property. Below is the code responsible for dispatching events before saving data:

268
269
270
271
272
273
    protected function _beforeSave()
    {
        Mage::dispatchEvent('model_save_before', array('object'=>$this));
        Mage::dispatchEvent($this->_eventPrefix.'_save_before', array($this->_eventObject=>$this));
        return $this;
    }

The $_eventPrefix could be used in your own models, but you can also make use of it in some of Magento classes. So instead of listening to ‘model_save_before’ event when dealing with customer model, you can wait for ‘customer_save_before’.

,

One Response to “Event prefix in Magento models”

  • April

    Pretty good post. I just came by your site and wanted to say
    that I have really enjoyed browsing your blog posts. Any way
    I’ll be subscribing to your feed and I hope you write again soon!

Add reply