Magento create invoice programmatically

$order_id = 1;
 $order = Mage::getModel("sales/order")->load($order_id);

try {

if(!$order->canInvoice())
 {
 Mage::throwException(Mage::helper('core')->__('Cannot create an invoice...'));
 }

$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();

if (!$invoice->getTotalQty()) {
 Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
 }

$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::NOT_CAPTURE);

$invoice->register();
 $transactionSave = Mage::getModel('core/resource_transaction')
 ->addObject($invoice)
 ->addObject($invoice->getOrder());

$transactionSave->save();

}
 catch (Mage_Core_Exception $e) {
 echo $e->getMessage();
 }
Advertisements

Published by

samrat131

Hello, I am a software developer from Bangladesh. I develop professional web sites/applications using LAMP(Linux, Apache, MySql, PHP) Stack. I have 7 years of professional working experience developing websites on WordPress, Magento, Laravel, Yii, Code Igniter. I have in depth knowledge on following language and tools, PHP, C, C++, Java, MySql, HTML(5), CSS(3), JavaScript, jQuery, Linux, Windows, Apache, Ngnix.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s