Magento create invoice of specific order by programmatically

<?php
require_once('app/Mage.php');
Mage::app();


$orderId = '10508'; /////$order->getId();
$fullOrder = Mage::getModel('sales/order')->load($orderId);
$fullOrder->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true);
$fullOrder->setStatus('processing', false);
$fullOrder->save();
try {
if(!$fullOrder->canInvoice()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));
}
$invoice = Mage::getModel('sales/service_order', $fullOrder)->prepareInvoice();
if (!$invoice->getTotalQty()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
}
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder());
$transactionSave->save();
} catch (Mage_Core_Exception $e) {
}


?>
$order->getId();  = here your magento order id....

Comments

  1. Was great to work with. Got the tasks done in a timely manner. Look forward to working on next project.

    ReplyDelete

Post a Comment

Popular posts from this blog

Adding Contact us link to Top Menu in Magento

Credit card number for Testing payment methods