Magento – automatically email invoice and shipment after creating

invoiceshipment

How can I make magento automatically email invoice/shipment after I create them.

what happens now is that:

1) I a create the invoice/shipment and then

2) I open the invoice/shipment and press send email.

I don't want to do the second step, I want the email to be send once the invoice/shipment created.

Best Answer

you need to look at this magento event sales_order_shipment_save_after.

So in app/code/local/Namespace/Module/etc/config.xml:

...
<events>
    <sales_order_shipment_save_after>
    <observers>
        <namespace_module>
        <type>singleton</type>
        <class>Namespace_Module_Model_Observer</class>
        <method>autoEmail</method>
        </namespace_module>
    </observers>
    </sales_order_shipment_save_after>
</events>
....

and in app/code/local/Namespace/Module/Model/Observer.php:

    <?php
    class Namespace_Module_Model_Observer
    {
       public function autoEmail($observer) {
           $shipment = $observer->getEvent()->getShipment();
           $order = $shipment->getOrder();
// your email triggering code here.
       }
    }