0

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

1 Answer 1

0

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.

7
  • The order status went to "pending" however it still went to "processing". I'll post a screenshot in my question.
    – p_jk
    Commented May 30, 2016 at 9:20
  • Make sure this module is working add Mage::log('working',null,'pay.log'); in implementOrderStatus function and see log folder
    – Arunendra
    Commented May 30, 2016 at 9:57
  • Yes, it worked and it created the pay.log file. The screenshot I posted has 2 "pending" statuses. The second "pending" status was because of the code you suggested. I think the observer should be called after "processing" status? I also have a feeling that it goes to "processing" because it auto generates an invoice however I can't find a way to try that yet (can't find anything in google lol). I had typo with this comment I just updated it.
    – p_jk
    Commented May 30, 2016 at 10:26
  • comment Mage::getModel('core/resource_transaction') ->addObject($invoice) ->addObject($invoice->getOrder()) ->save(); this line
    – Arunendra
    Commented May 30, 2016 at 10:27
  • please see the updated the answer
    – Arunendra
    Commented May 30, 2016 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.