Magento: Order has invoice (generated) but 'To

2019-04-02 12:11发布

问题:

I have a live Magento 1.5.0.1 webshop, with the following problem:

We have received an order, which has been paid for through iDEAL (Dutch online payment service) and an invoice has been auto-generated on payment success. We have also received the amount on our bank account.

The only thing is, we cannot complete the order because of the 'Total due' field being an amount higher than 0 (zero). This must be a bug in our iDEAL-module (which will be dealt with at another moment).

Is there a way to 'force' this particular order to be 'complete' with the Total due field set to 0?

Obviously, PHP-code examples to do so are quite welcome (I am a programmer myself).

回答1:

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.