How Can I Create Magento Invoice Programmatically

How can I create Magento invoice programmatically

You need to load Magento order first and then use “prepareInvoice” method to create Magento invoice

$orderid = 1;
$order = Mage::getModel("sales/order")->load($orderid );
if($order->canInvoice()){
    $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
    if($invoice->getTotalQty()){
        $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
        $invoice->register();
        $transactionSave = Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder());
        $transactionSave->save();
    }
}
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments