我正在尝试设置一个观察器,它将在订单完成时触发命令。我尝试将几个订单标记为完成,我的观察器未被触发。
.xml 在等/模块中
<?xml version="1.0"?>
<config>
<modules>
<Test_ReviewRequestTrigger>
<version>1.0</version>
</Test_ReviewRequestTrigger>
</modules>
<global>
<models>
<review_request_trigger>
<class>Test_ReviewRequestTrigger_Model</class>
</review_request_trigger>
</models>
<events>
<sales_order_save_after>
<observers>
<review_request_trigger>
<type>singleton</type>
<class>Test_ReviewRequestTrigger_Model_Observer</class>
<method>implementOrderStatus</method>
</review_request_trigger>
</observers>
</sales_order_save_after>
</events>
</global>
</config>
config.xml in app/code/.../ReviewRequestTrigger/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Test_ReviewRequestTrigger>
<active>true</active>
<codePool>local</codePool>
</Test_ReviewRequestTrigger>
</modules>
</config>
观察者.php在app/code/.../ReviewRequestTrigger/Model/Observer.php
class Test_ReviewRequestTrigger_Model_Observer
{
public function implementOrderStatus($event)
{
Mage::log("hello", null, 'test_ReviewRequestTrigger.log');
$order = $event->getOrder();
$stateProcessing = $order::STATE_COMPLETE;
// Only trigger when an order enters processing state.
if ($order->getState() == $stateProcessing && $order->getOrigData('state') != $stateProcessing) {
}
}
}
您的config.xml
文件中有几个错误可能是罪魁祸首。 以下是有关如何设置观察器的更多信息的链接,但以下是适用于您的问题的相关代码:
<events>
<sales_order_save_after>
<observers>
<ReviewRequestTrigger>
<type>singleton</type>
<class>ReviewRequestTrigger/observer</class>
<method>implementOrderStatus</method>
</ReviewRequestTrigger>
</observers>
</sales_order_save_after>
</events>
请注意对<ReviewRequestTrigger>
包装器和其中<class>
标记的更改。