How to create Magento invoice from order
来源:互联网 发布:ubuntu安装mac os 编辑:程序博客网 时间:2024/05/21 15:50
Maybe you want to create an invoice from some custom script or through cron script. Here is one very useful example of code.
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
0 0
- How to create Magento invoice from order
- How to extend Magento Order Grid?
- How to create custom price in Magento?
- How Does The Invoice Date Get Derived From The Sales Order Line? (文档 ID 300311.1)
- How to cancel an invoice
- How to create HBITMAP from WICBitmapSource
- How to create a server from scratch
- How To Migrate Magento From Development To Production Servers
- How to read data from a file in reverse order?
- How to create ArrayList (ArrayList from array (T[]) in Java
- How To Create manually an ASM Instance From Scratch
- How to create WSDL SourceCode from a webservice.
- How to create an EMF model from a Java application ?
- How to create XML validator from XML schema?
- How to create caffe.deploy from train.prototxt
- Magento - how to add custom variables to new order E-mail?
- Magento. How to create an attribute and apply it to products
- SD-How to get delivery plant when you use va01 to create a new order
- struts2 获得request,response,session
- Volatile: Almost Useless for Multi-Threaded Programming
- 辞掉工作去开发一个应用
- SHELL:getopts用法介绍
- C#--时间转换
- How to create Magento invoice from order
- Oracle自定义编码规则
- SQL优化-索引
- CodeForces 375A Divisible By Seven
- 【Android进阶学习】shape和selector的结合使用
- MFC- ActiveX编程(孙鑫C++第十八讲笔记整理 )
- TCP-socket(2)
- position属性absolute与relative 详解
- EXT Grid中添加人民币符号