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.