I have created a module for listening to the event sales_order_place_after
. I did it following the article http://www.atwix.com/magento/auto-invoice-and-custom-order-status-upon-checkout.
I use it for set my order to processing status, because it's always changed to pending that I set with new order status.
The module works in Magento 1.8.0, but it doesn't work in magento 1.9.1. How could I resolve this problem? Please help me
This is how the module is built:
First, I create a module initializer in /app/etc/modules/Atwix_Orderhook.xml with following content
<?xml version="1.0"?> <config> <modules> <Atwix_Orderhook> <active>true</active> <codePool>community</codePool> </Atwix_Orderhook> </modules> </config>
then I create a module configuration file /app/code/community/Atwix/Orderhook/etc/config.xml with content
<?xml version="1.0"?> <config> <modules> <Atwix_Orderhook> <version>1.0</version> </Atwix_Orderhook> </modules> <global> <models> <orderhook> <class>Atwix_Orderhook_Model</class> </orderhook> </models> <events> <sales_order_place_after> <observers> <auto_invoice_order> <type>singleton</type> <class>Atwix_Orderhook_Model_Observer</class> <method>implementOrderStatus</method> </auto_invoice_order> </observers> </sales_order_place_after> </events> </global> </config>
finally I create the app/code/community/Atwix/Orderhook/Observer.php with following content
<?php class Atwix_Orderhook_Model_Observer { public function implementOrderStatus($event) { $order = $event->getOrder(); if ($this->_getPaymentMethod($order) == 'cwinline') { $this->_processOrderStatus($order); } return $this; } private function _getPaymentMethod($order){ { return $order->getPayment()->getMethodInstance()->getCode(); } private function _processOrderStatus($order){ $status = $order->getPayment()->getStatus(); if($status=='SUCCESS'){ $this->_changeOrderStatus($order); } return true; } private function _changeOrderStatus($order){ $statusMessage = 'payment success'; $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING,Mage_Sales_Model_Order::STATE_PROCESSING,$statusMessage, false); $order->save(); } } ?>