From dbcf634a6c06e84349a84fb138b2f7d675b1558d Mon Sep 17 00:00:00 2001 From: Gytautas Date: Wed, 9 Oct 2024 10:30:51 +0300 Subject: [PATCH] fixed number utility for low ps version --- src/Utility/NumberUtility.php | 14 +++++++++----- views/css/admin/logs/index.php | 0 views/css/admin/logs/log.css | 0 views/js/admin/logs/index.php | 0 views/js/admin/logs/log.js | 0 views/templates/admin/logs/index.php | 0 views/templates/admin/logs/log_modal.tpl | 0 .../templates/admin/logs/severity_level_column.tpl | 0 views/templates/admin/logs/severity_levels.tpl | 0 9 files changed, 9 insertions(+), 5 deletions(-) mode change 100755 => 100644 views/css/admin/logs/index.php mode change 100755 => 100644 views/css/admin/logs/log.css mode change 100755 => 100644 views/js/admin/logs/index.php mode change 100755 => 100644 views/js/admin/logs/log.js mode change 100755 => 100644 views/templates/admin/logs/index.php mode change 100755 => 100644 views/templates/admin/logs/log_modal.tpl mode change 100755 => 100644 views/templates/admin/logs/severity_level_column.tpl mode change 100755 => 100644 views/templates/admin/logs/severity_levels.tpl diff --git a/src/Utility/NumberUtility.php b/src/Utility/NumberUtility.php index 24fba4584..a0cc74de6 100644 --- a/src/Utility/NumberUtility.php +++ b/src/Utility/NumberUtility.php @@ -14,6 +14,7 @@ use PrestaShop\Decimal\DecimalNumber; use PrestaShop\Decimal\Exception\DivisionByZeroException; +use PrestaShop\Decimal\Number; use PrestaShop\Decimal\Operation\Rounding; if (!defined('_PS_VERSION_')) { @@ -228,15 +229,18 @@ public static function plus(float $a, float $b): float } /** - * Creates a Number or DecimalNumber instance from a float. + * Creates a Number or DecimalNumber instance based on the current environment. * * @param float $number * - * @return DecimalNumber + * @return DecimalNumber|Number */ - private static function getNumber(float $number): DecimalNumber + private static function getNumber(float $number) { - // Assuming DecimalNumber is the preferred class based on the use case. - return new DecimalNumber((string) $number); + if (is_subclass_of(Number::class, DecimalNumber::class)) { + return new DecimalNumber((string) $number); + } + + return new Number((string) $number); } } diff --git a/views/css/admin/logs/index.php b/views/css/admin/logs/index.php old mode 100755 new mode 100644 diff --git a/views/css/admin/logs/log.css b/views/css/admin/logs/log.css old mode 100755 new mode 100644 diff --git a/views/js/admin/logs/index.php b/views/js/admin/logs/index.php old mode 100755 new mode 100644 diff --git a/views/js/admin/logs/log.js b/views/js/admin/logs/log.js old mode 100755 new mode 100644 diff --git a/views/templates/admin/logs/index.php b/views/templates/admin/logs/index.php old mode 100755 new mode 100644 diff --git a/views/templates/admin/logs/log_modal.tpl b/views/templates/admin/logs/log_modal.tpl old mode 100755 new mode 100644 diff --git a/views/templates/admin/logs/severity_level_column.tpl b/views/templates/admin/logs/severity_level_column.tpl old mode 100755 new mode 100644 diff --git a/views/templates/admin/logs/severity_levels.tpl b/views/templates/admin/logs/severity_levels.tpl old mode 100755 new mode 100644