为了开发基于付款方式和事件类型的自动订单状态更改器,我创建了以下模块:
/GT/OrderFlo/etc/config.xml
<!--?xml version="1.0"?-->
<config>
<modules>
<gt_orderflow>
<version>1.0</version>
</gt_orderflow>
</modules>
<global>
<models>
<orderflow>
<class>GT_OrderFlow_Model</class>
</orderhook>
</models>
<events>
<sales_order_place_after>
<observers>
<order_payment_pending_autostatus>
<type>singleton</type>
<class>orderflow/observer</class>
<method>implementOrderStatus</method>
</order_payment_pending_autostatus>
</observers>
</sales_order_place_after>
<sales_order_shipment_save_after>
<observers>
<order_invoice_pending_autostatus>
<type>singleton</type>
<class>orderflow/observer</class>
<method>implementOrderStatus</method>
</order_invoice_pending_autostatus>
</observers>
</sales_order_shipment_save_after>
<sales_order_invoice_save_commit_after>
<observers>
<order_complete_autostatus>
<type>singleton</type>
<class>orderflow/observer</class>
<method>implementOrderStatus</method>
</order_complete_autostatus>
</observers>
</sales_order_invoice_save_commit_after>
</events>
</global>
</config>
/GT/OrderFlow/Model/Observer.php
class GT_OrderFlow_Model_Observer
{
public function implementOrderStatus($event)
{
$order = $event->getOrder();
$payment_method = $this->_getPaymentMethod($order);
$this->_log('In implementOrderStatus with payment method: '.$payment_method);
Mage::log('In implementOrderStatus with payment method: '.$payment_method);
$next_status = "";
return $this;
}
private function _getPaymentMethod($order)
{
return $order->getPayment()->getMethodInstance()->getCode();
}
private function _log($message)
{
return Mage::log($message, null, 'gt_orderflow.log');
}
}
该代码是从http://www.atwix.com/magento/auto-invoice-and-custom-order-status-upon-checkout/复制而来的。
但是我怎样才能让它在sales_order_place_after
事件发生后解雇观察者呢?