php发票代码未正确更新订单

时间:2011-06-30 16:03:19

标签: php magento invoice

我实际上看不出原因,但是我的发票代码在完成而没有错误时实际上并没有显示总数的正确值。

代码是:

public function invoice($realOrderId){
$orderObj = Mage::getModel('sales/order')->loadByIncrementId($realOrderId);     
$invoice = Mage::getModel('sales/service_order', $orderObj)->prepareInvoice();
$invoice->addComment('Automatic invoice', false);
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->register();
$invoice->getOrder()->setIsInProcess(true);
$transactionSave = Mage::getModel('core/resource_transaction')
                   ->addObject($invoice)
                   ->addObject($invoice->getOrder());
$transactionSave->save();
    $invoice->sendEmail();
    $invoice->setEmailSent(true);
    $invoice->save();
}

代码可以正常运行而不会产生错误,但订单详细信息中的总数并未显示付款已被捕获!

关于可能出现什么问题的任何建议?

1 个答案:

答案 0 :(得分:3)

好吧,我设法使代码按预期工作,这里修正了函数,以防其他人可能需要它:

public function invoice($realOrderId){
$orderObj = Mage::getModel('sales/order')->loadByIncrementId($realOrderId);
$invoice = Mage::getModel('sales/service_order', $orderObj)->prepareInvoice();
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')
                   ->addObject($invoice)
                   ->addObject($invoice->getOrder());
$transactionSave->save();

$invoice->addComment('Automatic Invoice', false);
$invoice->sendEmail();
$invoice->setEmailSent(true);
$invoice->save();
$orderObj->addStatusHistoryComment(Mage::helper('<your helper name>')->__('Automatic Invoice: '.$invoice->getIncrementId()));
$orderObj->save();}

享受。

编辑: 忘记更正代码,避免在开具虚拟产品时出现“错误”,当代码在状态历史记录中设置注释时,状态可以省略。