下订单后创建发票

时间:2014-10-29 13:18:15

标签: php magento

我已经创建了我的自定义付款模块,它适用于支付网关,一切正常,但我想在返回网址返回成功代码时将订单设置为付费。到目前为止,我已经明白,我必须为订单创建一个发票,以便能够将其设置为支付到Magento面板。

首先,请告诉我,如果我在这儿之前就已经死了。

然后我尝试在success.phtml上创建发票,其代码如下:

$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();

但它总是给我一个magento错误,所以可能不是一个好主意。

任何帮助将不胜感激

修改

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

我用过

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

代替上面的代码,似乎支付了订单。但我不确定,如果已经足够了。

1 个答案:

答案 0 :(得分:4)

我建议您在客户从支付网关返回您的网站时,然后必须转到magento控制器,并在此处添加代码所需的操作

  $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)};
}

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

相关问题