Magento invoice - How to Generating(create) automatically invoice after the orders are shipped in Magento | Magento Source24

Hello friends today's i'm share How to Generating(create) automatically invoice after the orders are shipped in Magento


How to Generating(create) automatically invoice after the orders are shipped in Magento

👉 Create module config file : app\etc\modules\Magespy_Autoinvoice.xml


<config>
    <modules>
        <Magespy_Autoinvoice>
            <active>true</active>
            <codePool>local</codePool>
        </Magespy_Autoinvoice>
    </modules>
</config>


👉 I'd go the creating an event observer for sales_order_shipment_save_after:

👉 File path: app/code/local/Magespy/Autoinvoice/etc/config.xml


<? xml version = "1.0" ?>
<config>
    <modules>
        <Magespy_Autoinvoice>
            <version>0.1.0</version>
        </Magespy_Autoinvoice>
    </modules>
    <global>
        <events>
            <sales_order_shipment_save_after>
                <observers>
                    <magespy_autoinvoice>
                        <type>singleton</type>
                        <class>Magespy_Autoinvoice_Model_Observer</class>
                        <method>autoInvoice</method>
                    </magespy_autoinvoice>
                </observers>
            </sales_order_shipment_save_after>
        </events>
    </global>
</config>


👉 Now, we create one observer file : 

👉app\code\local\Magespy\Autoinvoice\Model\Observer.php


<?php

class Magespy_Autoinvoice_Model_Observer {

    public function autoInvoice($observer) {
        $shipment = $observer->getEvent()->getShipment();
        $order = $shipment->getOrder();
        if ($order->canInvoice()) {
            $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
            $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
            $invoice->register();
            $transactionSave = Mage::getModel('core/resource_transaction')
                    ->addObject($invoice)
                    ->addObject($invoice->getOrder());
            $transactionSave->save();
        }
    }

}





Deepak Kumar Bind

Success is peace of mind, which is a direct result of self-satisfaction in knowing you made the effort to become the best of which you are capable.

Post a Comment

If you liked this post please do not forget to leave a comment. Thanks

Previous Post Next Post