Merge pull request #1091 from sumitwebkul/gli-2160

Fixed: Fatal error occurs when adding negative price with an absolute numeric value equal to or less than the paid amount but a greater currency value
This commit is contained in:
Rohit Jain
2024-05-30 13:13:40 +05:30
committed by GitHub

View File

@@ -1612,9 +1612,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'),