Magento: Order has invoice (generated) but 'Total due' > 0

不羁岁月 提交于 2019-12-03 21:31:22

This might help you.

Example from one of our modules:

$order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
if ($order->getTotalPaid() == 0) {
    $invoice = $order->prepareInvoice();
    $invoice->register()->capture();
    Mage::getModel('core/resource_transaction')
        ->addObject($invoice)
        ->addObject($invoice->getOrder())
        ->save();
    $order->save();

This checks if payment was not yet registered(user might send several successful requests by multi clicking) then creates invoice, registers it, captures and save invoice and orders.

EDIT 1

private function markOrderPayd($incrementId, $status) {
        $order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
        if ($order->getTotalPaid() == 0) {
            ... 
            $order->save();
            $invoice = $order->prepareInvoice();
            $invoice->register()->capture();
            ...
            Mage::getModel('core/resource_transaction')
                ->addObject($invoice)
                ->addObject($invoice->getOrder())
                ->save();
            $order->save();
            ...

        } else {
            ...
            $order->save();
        }
}

I guess you don't have any check, so 2 invoices are generated.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!