Magento – Please help me set new order status for bank transfer payment to pending

magento-1.9order-statuspayment-banktransfer

I went to Admin Panel > Sales > Payment Methods > Bank Transfer Payment > New Order Status. I updated it to "pending" however when I place a new order the status still went to "processing".

I tried this. I went to code/core/Mage/Sales/Model/Order/Payment.php:

protected function _authorize($isOnline, $amount)
{
    // update totals
    $amount = $this->_formatAmount($amount, true);
    $this->setBaseAmountAuthorized($amount);

    // do authorization
    $order  = $this->getOrder();
    $state  = Mage_Sales_Model_Order::STATE_PROCESSING;
    $status = true;

I changed the STATE_PROCESSING to STATE_NEW to set it on "pending" but when I place a new order the status still went to "processing".

My Reference

How can I change the new order status to pending for bank transfer?

My Magento version is 1.9.0.1

Here's the screenshot:

enter image description here

Best Answer

Using a custom Magento module can do this task. Let’s name it Atwix_Orderhook.

Step 1 : First,Create a module initializer in /app/etc/modules/Atwix_Orderhook.xml with the following content:

<?xml version="1.0"?>
<config>
    <modules>
        <Atwix_Orderhook>
            <active>true</active>
            <codePool>community</codePool>
        </Atwix_Orderhook>
    </modules>
</config>

Step 2: Create a module configuration file config.xml in /app/code/community/NAMESPACE/MODULENAME/etc/ (replace NAMESPACE and MODULENAME with your own values). In our case the path will be /app/code/community/Atwix/Orderhook/etc/. config.xml 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>

Step 3 Create observer file app/code/community/Atwix/Orderhook/Model/Observer.php with the following content:

<?php
 
class Atwix_Orderhook_Model_Observer 
{
    public function implementOrderStatus($event)
    {
        $order = $event->getOrder();
 
        if ($this->_getPaymentMethod($order) == 'banktransfer') {
            if ($order->canInvoice())
                $this->_processOrderStatus($order);
        }
        return $this;
    }
 
    private function _getPaymentMethod($order)
    {
        return $order->getPayment()->getMethodInstance()->getCode();
    }
 
    private function _processOrderStatus($order)
    {
        $invoice = $order->prepareInvoice();
 
        $invoice->register();
      /*  Mage::getModel('core/resource_transaction')
           ->addObject($invoice)
           ->addObject($invoice->getOrder())
           ->save();*/
 
        $invoice->sendEmail(true, '');
        $this->_changeOrderStatus($order);
        return true;
    }
 
    private function _changeOrderStatus($order)
    {
        $statusMessage = '';
        $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true);        
    $order->save();
    }
}

Save this module and clear your cache. For more see here.