Magento: Quick way to create order invoice programmatically
Here is a quick and easy way to create order invoice programmatically.
Suppose, $_order contains your order.
Here goes the code to create invoice:-
if($_order->canInvoice()) {
/**
* Create invoice
* The invoice will be in 'Pending' state
*/
$invoiceId = Mage::getModel('sales/order_invoice_api')
->create($_order->getIncrementId(), array());
$invoice = Mage::getModel('sales/order_invoice')
->loadByIncrementId($invoiceId);
/**
* Pay invoice
* i.e. the invoice state is now changed to 'Paid'
*/
$invoice->capture()->save();
}
That’s all. Your invoice for the order is created. Isn’t that easy :)
Hope this helps. Thanks.
Related posts:
- Magento: How to change order status programmatically?
- Magento: Create CMS Page & Static Block programmatically
- Magento: Create Catalog Price Rule Programmatically
- Magento: Set Random Order in Collection using RAND()
- Magento: Displaying / Adding Gift Message in Order
- Magento: Create Shopping Cart Price Rule Programmatically
- Magento: Get order option of configurable and bundle product in cart
- jQuery: Grey out background and preview image as popup
- Magento: How to enable backorders?
- Magento: Create Watermark Image
