Magento Forum

   
Event-Dispatch Problem from Admin interface
 
jhutton
Jr. Member
 
Total Posts:  19
Joined:  2008-06-24
 

I have a custom module which has an observer set on the ‘sales_order_place_after’ event. When I place an order through the checkout process on the front end, the callback method gets executed. However, when I place an order for a customer through the admin interface, the callback is not executed, even though the event is apparently dispatched.

In Mage/Sales/Model/Order.php I have:

public function place()
    
{
        $this
->_placePayment();
        
Mage::log("calling dispatch");
        
Mage::dispatchEvent('sales_order_place_after', array('order'=>$this));
        
Mage::log("called dispatch");
        return 
$this;
    
}

In my call back I have some log messages. An order from the front end results in this in the log:

009-01-23T01:37:54+00:00 DEBUG (7): calling dispatch
2009
-01-23T01:37:54+00:00 DEBUG (7): callback executed
2009
-01-23T01:37:55+00:00 DEBUG (7): found workshop
...
2009-01-23T01:38:02+00:00 DEBUG (7): called dispatch

The log message from an order placed in the admin results in:

2009-01-23T01:39:35+00:00 DEBUG (7): calling dispatch
2009
-01-23T01:39:35+00:00 DEBUG (7): called dispatch

My modules config is:

<events>
      <
sales_order_place_after>
        <
observers>
          <
xyz_class_workshop_observer>
            <
type>singleton</type>
            <class>
xyz_class/observer</class>
            <
method>registerCustomerWithEventlist</method>
          </
xyz_class_workshop_observer>
        </
observers>
      </
sales_order_place_after>
    </
events>

Can anyone shed some light onto what is going on here?

 
Magento Community Magento Community
Magento Community
Magento Community
 
jhutton
Jr. Member
 
Total Posts:  19
Joined:  2008-06-24
 

OK, I believe I found the answer, not one minute after posting. The config has a separate section for adminhtml events...ugh.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jhutton
Jr. Member
 
Total Posts:  19
Joined:  2008-06-24
 

If anyone is listening, I’m facing another problem now. From the back end I get a quote object from the order that’s passed to the event and then call getAllItems() on the quote (later checking the product attributes set of the items). When running this from the back end, I get 0 items from the quote. If I look it up after the transaction, after the fact, I can access the quote items. And of course, the callback from the checkout process can access the quote items…

So, why do I get 0 quote items from an order on a callback (which is now firing on ‘sales_order_after_save’) from the backend?

 
Magento Community Magento Community
Magento Community
Magento Community
 
jhutton
Jr. Member
 
Total Posts:  19
Joined:  2008-06-24
 

The basic workaround seems to be to get products like so (which works from Order Items):

foreach($items as $item{
$product 
Mage::getModel('catalog/product')->load($item->getProductId());
// product checking logic
}

Calling $item->getProduct() from a Quote item doesn’t seem to always work…

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top