From 1374260462f42d5ecdaeddfae82dfa1cbc0f99ad Mon Sep 17 00:00:00 2001 From: Sumit Panwar Date: Wed, 29 May 2024 11:29:17 +0530 Subject: [PATCH] Fixed:A fatal error occurs when adding a negative price with an absolute numeric value equal to or less than the paid amount but a greater currency value --- controllers/admin/AdminOrdersController.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index c08b5f111..476f5b4a5 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -1624,9 +1624,21 @@ class AdminOrdersControllerCore extends AdminController } elseif (!Validate::isUnsignedInt($payment_type)) { $this->errors[] = Tools::displayError('Payment source is invalid'); // Amount cannot be less than paid amount by guest in negative price - } elseif ($amount < 0 && ($order->total_paid_real + $amount) < 0) { - $this->errors[] = sprintf(Tools::displayError('Amount cannot be less than -%s'), Tools::displayPrice($order->total_paid_real, new Currency($order->id_currency))); - } else { + } elseif ($amount < 0) { + if ($currency->id == $order->id_currency) { + if (($order->total_paid_real + $amount) < 0) { + $this->errors[] = sprintf(Tools::displayError('Amount cannot be less than -%s'), Tools::displayPrice($order->total_paid_real, new Currency($order->id_currency))); + } + } else { + $convertedAmount = Tools::ps_round(Tools::convertPriceFull($amount, $currency, new Currency($order->id_currency)), 6); + $convertedPaidAmount = Tools::ps_round(Tools::convertPriceFull($order->total_paid_real, new Currency($order->id_currency), $currency), 6); + if (($order->total_paid_real + $convertedAmount) < 0) { + $this->errors[] = sprintf(Tools::displayError('Amount cannot be less than -%s (-%s)'), Tools::displayPrice($convertedPaidAmount, $currency), Tools::displayPrice($order->total_paid_real, new Currency($order->id_currency))); + } + } + } + + if (!count($this->errors)) { if (!$order->addOrderPayment( $amount, Tools::getValue('payment_method'),