Pages

Monday, 23 June 2014

Create Invoice Programmatically in magento

If you have not read previous articles yet, I strongly advise you to do so.  Here I will explain how to create invoice Programmatically.
For automization magento we required auto create a invoice .

therefor I decide to write blog for create invoice by code so after placing an order it will auto generate invoice .

 Following are the steps for create a invoice .

 step 1: create invoice by code
   $order_id = "100000004";
//load order by increment id
        $order = Mage::getModel("sales/order")->loadByIncrementId($order_id);
        try {
            if($order->canInvoice()) {
                //Create invoice with pending status
                $invoiceId = Mage::getModel('sales/order_invoice_api')
                    ->create($order->getIncrementId(), array());

                $invoice = Mage::getModel('sales/order_invoice')
                    ->loadByIncrementId($invoiceId);

                //set invoice status "paid"
                $invoice->capture()->save();
                $this->_redirect('test/index/index');
            }
        }catch (Mage_Core_Exception $e) {
            print_r($e->getMessage());
        }


If run above code successfully created the invoice.

Create Invoice Programmatically in magento
If you have any queries please leave a comment.

No comments:

Post a Comment