How to create Magento invoice from order
2013-12-25 11:39
260 查看
Maybe you want to create an invoice from some custom script or through cron script. Here is one very useful example of code.
First of all, we have to load some order over model “sales/order”, this is very easy.
Next step, when we have loaded model “sales/ored” with data, the next procedure is:
You will notice that we have set option for capture online. This option depends on payment method. Some payment methods support capture online and some don’t. If you want to set capture offline, you can do that with next line code:
hope that this is clear
First of all, we have to load some order over model “sales/order”, this is very easy.
$order = Mage::getModel("sales/order")->load($order_id)
Next step, when we have loaded model “sales/ored” with data, the next procedure is:
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::CAPTURE_ONLINE); $invoice->register(); $transactionSave = Mage::getModel('core/resource_transaction') ->addObject($invoice) ->addObject($invoice->getOrder()); $transactionSave->save(); } catch (Mage_Core_Exception $e) { }
You will notice that we have set option for capture online. This option depends on payment method. Some payment methods support capture online and some don’t. If you want to set capture offline, you can do that with next line code:
$invoice->setRequestedCaptureCase( Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE );
hope that this is clear
![](http://inchoo.net/wp-includes/images/smilies/icon_smile.gif)
相关文章推荐
- How to create physical standby database with 11g RMAN DUPLICATE FROM ACTIVE DATABASE [ID 747250.1]
- Magento - how to add custom variables to new order E-mail?
- How to read data from a file in reverse order?
- How to create a hex dump from binary data in C++
- Oracle:How to create physical standby database with 11g RMAN DUPLICATE FROM ACTIVE DATABASE [ID 747250.1]
- How to create WSDL SourceCode from a webservice.
- How to create physical standby database with 11g RMAN DUPLICATE FROM ACTIVE DATABASE [ID 747250.1]
- How to use CreateChildContorls method inherited from System.Web.UI.Control
- ioS:How to create a ARGB CGImageRef from a ABGR CGImageRef in Cocoa
- How to create custom price in Magento?
- How to create an XTR file from XML in Delphi XE4 using XML Mapper?(delphi中如何通过xmlmapper创建xtr文件)
- How to extend Magento Order Grid?
- How to create physical standby database with 11g RMAN DUPLICATE FROM ACTIVE DATABASE [ID 747250.1]
- How to create a virtual machine from a physical one(转)
- How To Migrate Magento From Development To Production Servers
- How to create physical standby database with 11g RMAN DUPLICATE FROM ACTIVE DATABASE [ID 747250.1]
- How to create an EMF model from a Java application ?
- How to create a project from existing source in Eclipse and then find it?
- How to create physical standby database with 11g RMAN DUPLICATE FROM ACTIVE DATABASE [ID 747250.1]
- How To Create manually an ASM Instance From Scratch