mollie / Magento

Mollie Payments for Magento 1.x
https://www.mollie.com/
BSD 2-Clause "Simplified" License
39 stars 30 forks source link

qty_invoiced on order items not set with Klarna Pay Later invoice #196

Closed mybinaryromance closed 3 years ago

mybinaryromance commented 3 years ago

When creating the invoice on Klarna Pay Later payment method, the qty_invoiced is not set for the order items. This leads to the problem that no creditmemo can be created for these orders resp. the creditmemo has an amount of 0.

Please use Mage_Sales_Model_Order_Invoice_Api for invoice creation in app/code/community/Mollie/Mpm/Model/Client/Orders.php

Frank-Magmodules commented 3 years ago

Hi @mybinaryromance , Thank you for opening and reporting this issue and sorry for the late response to your ticket. We have created an internal task for this issue and will try to come back to you as soon as possible. Thank you for your patience!

mybinaryromance commented 3 years ago

I have investigated the issue a little further and would like to share my findings.

A quick workaround might be to call the $invoice->register() method for every invoice creation but making the capture process in Mage_Sales_Model_Order_Invoice::register() itself fail by making "if ($captureCase)" (around line 650) fail. This might be easily achieved by rewriting Mollie_Mpm_Model_Client_Orders lines 265ff like this:

$invoice = $order->prepareInvoice();                            
$invoiceStatus = $this->mollieHelper->getInvoiceMomentPaidStatus($order);

                            if ($invoiceStatus != \Mage_Sales_Model_Order_Invoice::STATE_PAID) { //we dont want to pay order now
                                $invoice->setRequestedCaptureCase(NULL); //force no capture by causing  "if ($captureCase)" to fail, see Mage_Sales_Model_Order_Invoice::register()
                                $invoice->register(); //register without capture
                                $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE); //set capture scenario for later use
                            } else { //normal behaviour, capture resp pay on invoice creation
                                $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
                                $invoice->register();
                            }
                            $invoice->setTransactionId($transactionId);
                            $invoice->setState($invoiceStatus);

                            Mage::getModel('core/resource_transaction')
                                ->addObject($invoice)
                                ->addObject($invoice->getOrder())
                                ->save();
Frank-Magmodules commented 3 years ago

HI @mybinaryromance ,

We are happy to share that we've just released the new 5.6.5 version with a fix for this issue. Thank you again for the detailed reports and patience. We are closing this issue now but please feel free to reopen the issue if this still occurs.