Magento: observer data not being passed to function?

时间:2015-07-31 19:21:39

标签: magento

I have written a magento observer that monitors the sales_order_place_after events in both the frontend and adminhtml portions of the site. The purpose of this is to simply grab the completed order info, and use it to send a secondary transactional email based on the country of shipping for the order.

I have setup my module config.xml like this:

<adminhtml>
<events>
    <sales_order_place_after>
        <observers>
            <internationalemail>
                <type>singleton</type>
                <class>MGD_Internationalemail_Model_Observer</class>
                <method>sendInternationalEmail</method>
            </internationalemail>
        </observers>
    </sales_order_place_after>     
</events>
</adminhtml>
 <frontend>
    <events>
        <sales_order_place_after>
            <observers>
                <internationalemail>
                    <type>singleton</type>
                    <class>MGD_Internationalemail_Model_Observer</class>
                    <method>sendInternationalEmail</method>
                </internationalemail>
            </observers>
        </sales_order_place_after>     
    </events>
 </frontend>

And my model like this:

class MGD_Internationalemail_Model_Observer extends Varien_Event_Observer {

    public function sendInternationalEmail($observer) {

        Mage::log("---International Email Check ---");

        Mage::log($observer->getOrder());
    }
}

For some reason, when I submit a transaction, I get the "email check" in the log but the execution hangs and eventually times out, when I try to get the order and dump. No exception is thrown.

I cannot print_r or output $observer at all, which leads me to believe its not being populated. What am I missing here?

Thanks in Advance!

1 个答案:

答案 0 :(得分:2)

  

但执行挂起并最终超时

这通常是对象太大和/或具有循环引用的结果,并且PHP试图将整个事物呈现为字符串。

尝试使用其中一个(或全部)代替(可能的拼写错误,未经测试的伪代码)

Mage::Log(get_class($observer->getOrder()));
Mage::Log(array_keys($observer->getData()));
foreach($observer->getData() as $key=>$object)
{
    Mage::Log($key . '::' . get_class($object));
}
//Mage::Log($observer->getOrder());