【问题标题】:php Invoice code not updating correctly the orderphp发票代码未正确更新订单
【发布时间】:2011-06-30 16:03:19
【问题描述】:

我实际上不明白为什么,但我的发票代码在完成时并没有显示正确的总计值。

代码是:

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

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

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

【问题讨论】:

  • 总数有多不正确?他们是按税额计算的吗? (我想我也有类似的经历)
  • 订单页面(管理员视图)中的总数没有考虑到付款已完成的事实,在“总付款”部分,他们列出了 0,00
  • 抱歉,我不是这么想的。也许订单对象没有与之关联的付款。或者付款的_canCapture 是假的。或者总计没有以某种方式复制到发票中。想一想,有很多可能性。
  • 我正在检查,据我所知,_canCapture 返回 true,但是,是的,似乎有人没有将总数移到发票中,表格显示专用于即使方法 register(); 发票总额为空;应该通过方法 pay() 处理它;在同一个模型中定义,可能是一些非常愚蠢和明显的东西,会阻止正确的过程

标签: php magento invoice


【解决方案1】:

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

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

享受吧。

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

【讨论】:

    猜你喜欢
    • 2011-10-07
    • 1970-01-01
    • 2021-09-02
    • 1970-01-01
    • 2016-08-23
    • 1970-01-01
    • 2021-03-31
    • 2012-04-30
    • 1970-01-01
    相关资源
    最近更新 更多