我正在尝试订阅Magento中的sales_order_place_after
观察者,以便我可以输出订单数据。不幸的是,无论何时我尝试将输出记录到Mage :: log,print_r,甚至var_dump,我都会收到User Error: Some transactions have not been committed or rolled back
错误。
注意我正在使用一步结账并且结帐通常挂起(确认电子邮件仍然存在)可能也很重要。挂起后不久,我收到PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 234881024 bytes)
错误。似乎无法追踪导致内存泄漏的位置或原因...但是如果我尝试输出数据,则此错误仅会吐出。
config.xml中
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<InfinitelyWhite_OrderEvent>
<version>0.0.1</version>
</InfinitelyWhite_OrderEvent>
</modules>
<!-- Configure our module's behavior in the global scope -->
<global>
<!-- Defining models -->
<models>
<!--
Unique identifier in the model's node.
By convention, we put the module's name in lowercase.
-->
<infinitelywhite_orderevent>
<!--
The path to our models directory, with directory
separators replaced by underscores
-->
<class>InfinitelyWhite_OrderEvent_Model</class>
</infinitelywhite_orderevent>
</models>
<events>
<sales_order_place_after>
<observers>
<infinitelywhite_orderevent>
<class>infinitelywhite_orderevent/observer</class>
<method>exportNewOrder</method>
<type>singleton</type>
</infinitelywhite_orderevent >
</observers>
</sales_order_place_after>
</events>
</global>
Observer.php
class InfinitelyWhite_OrderEvent_Model_Observer
{
/**
* Magento passes a Varien_Event_Observer object as
* the first parameter of dispatched events.
*/
public function exportNewOrder(Varien_Event_Observer $observer)
{
Mage::log('reached export_new_order');
$order = $observer->getOrder();
Mage::log($order->getData());
return $this;
}
}
非常感谢任何帮助。
答案 0 :(得分:1)
Nick Parson .....请删除单身人士
<type>singleton</type>
答案 1 :(得分:1)
当正确的方法是使用$observer->getOrder()
时,原因是错误即将发生,因为我试图使用$observer->getEvent()->getOrder()
提取订单信息。我只是错过了getEvent()
。
我现在能够像这样提取数据:
$order = $observer->getEvent()->getOrder();
$billing = $order->getBillingAddress();
$shipping = $order->getShippingAddress();
$customer = $order->getCustomer();
然后我可以做类似的事情:
$order->getData()
或$customer->getData()
同样重要的是要注意,因为我关闭了观察者事件而我没有使用sales_model_service_quote_submit_success
来阻止讨厌的User Error: Some transactions have not been committed or rolled back error
。
答案 2 :(得分:0)
无法发表评论,但如果禁用观察者会怎样? (只是为了确保它是造成这个问题的观察者)。
如果是观察者,您可以尝试将$order->getData()
替换为$order->debug()
并查看是否有帮助