duanen19871021 2014-10-29 13:18
浏览 96
已采纳

下订单后创建发票

I've create my custom payment module, it works on payment gateway, everything is working fine but I would like to set the order as paid when the return url give back a succes code. So far I've understand that I have to create an invoice for the order to be able to ave it set as paid into Magento panel.

So first of all please tell me if I'm wron until here.

Then I'm trying to create invoice on success.phtml with some codes like:

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


        $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
        $invoice->register();

        $invoice->getOrder()->setCustomerNoteNotify(true);          
        $invoice->getOrder()->setIsInProcess(true);
        $order->addStatusHistoryComment('Automatically INVOICED by Rico.', false);

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

        $transactionSave->save();

But it gives me back always a magento error, so probably is not a good idea.

Any help will be appreciated

EDIT

From this http://blog.chapagain.com.np/magento-quick-way-to-create-order-invoice-programmatically/

I've used

$invoiceId = Mage::getModel('sales/order_invoice_api')
                        ->create($_order->getIncrementId(), array());

instead the code above and it seems that the order is paid. But I'm not sure, if is enough.

  • 写回答

1条回答 默认 最新

  • douquanzhan0315 2014-10-29 16:44
    关注

    I suggest you when customer is returning to your site from payment gateway and then it must goes to a magento controller and it an action you need to add your code at there

      $order=Mage::getModel('sales/order')->load($orderID);
    if($order->canInvoice() and $order->getIncrementId())
    {
      $items = array();
      foreach ($order->getAllItems() as $item) {
        $items[$item->getId()] = $item->getQtyOrdered();
      }
    $invoiceId=Mage::getModel('sales/order_invoice_api')->create($order->getIncrementId(),$items,null,false,true);
    Mage::getModel('sales/order_invoice_api')->capture($invoiceId)};
    }
    

    See http://www.amitbera.com/programmatically-create-invoice-of-a-new-order-in-magento/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?