I am trying to automatically send shipment email when an invoice is created for an order but I can't get me code to work…
Here is what I have:
config.xml
<?xml version="1.0"?>
<config>
<modules>
<Modulename_Invoicer>
<version>0.1.0</version>
</Modulename_Invoicer>
</modules>
<global>
<models>
<invoicer>
<class>Modulename_Invoicer_Model</class>
</invoicer>
</models>
<events>
<sales_order_save_after>
<observers>
<sales_order_save_after_handler>
<type>model</type>
<class>invoicer/observer</class>
<method>implementOrderStatus</method>
</sales_order_save_after_handler>
</observers>
</sales_order_save_after>
</events>
</global>
</config>
And Observer.php
<?php
class Namespace_Invoicer_Model_Observer
{
public function implementOrderStatus ($event)
{
$order = $event->getOrder ();
if ($this->_getPaymentMethod ($order) == 'ccsave') {
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 has been updated';
$order->setState (Mage_Sales_Model_Order::STATE_COMPLETE, true);
$order->save ();
}
}
I did follow this example from Inchoo if anyone has been able to get this to work please let me as I'm banging my head off of the desk…
Best Answer
As you said ,you want to send shipment mail after create Invoice.
For this ,you need change the event
from sales_order_save_after
tosales_order_invoice_register
which is better ...See more at
https://stackoverflow.com/questions/7661455/whats-the-event-name-when-you-create-a-new-invoice-in-magento
Run method after capturing invoice
Also Some issue in config.xml
Should be from
Namespace_Invoicer_Model_Observer
toinvoicer/observer
Also Observer file implementOrderStatus() , $Order have wrong parameterFor Doing shipment on Order all items try below code ,so processOrderStatus() code should be