From 5143da5b124644287607d3e9cd4bae24c3693665 Mon Sep 17 00:00:00 2001 From: Jetty Rohan Aditya Date: Thu, 31 Aug 2023 12:11:35 +0530 Subject: [PATCH 1/2] Precision issue solved --- app/code/Magento/Catalog/view/base/web/js/price-utils.js | 8 +++----- app/code/Magento/Directory/Model/PriceCurrency.php | 3 +-- app/code/Magento/Quote/Model/Quote/Item/AbstractItem.php | 2 +- .../Magento/Framework/Pricing/PriceCurrencyInterface.php | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Catalog/view/base/web/js/price-utils.js b/app/code/Magento/Catalog/view/base/web/js/price-utils.js index 840fdeb19ccb2..5233d6493f6d2 100644 --- a/app/code/Magento/Catalog/view/base/web/js/price-utils.js +++ b/app/code/Magento/Catalog/view/base/web/js/price-utils.js @@ -13,13 +13,12 @@ define([ 'use strict'; var globalPriceFormat = { - requiredPrecision: 2, + requiredPrecision:4, integerRequired: 1, decimalSymbol: ',', groupSymbol: ',', groupLength: ',' }; - /** * Repeats {string} {times} times * @param {String} string @@ -41,9 +40,8 @@ define([ { var s = '', precision, pattern, locale, r; - format = _.extend(globalPriceFormat, format); - precision = isNaN(format.requiredPrecision = Math.abs(format.requiredPrecision)) ? 2 : format.requiredPrecision; + precision = !isNaN(format.requiredPrecision = Math.abs(format.requiredPrecision)) ? 4 : format.requiredPrecision; pattern = format.pattern || '%s'; locale = window.LOCALE || 'en-US'; if (isShowSign === undefined || isShowSign === true) { @@ -76,7 +74,7 @@ define([ precision = isNaN(format.requiredPrecision = Math.abs(format.requiredPrecision)) ? 2 : format.requiredPrecision; integerRequired = isNaN(format.integerRequired = Math.abs(format.integerRequired)) ? 1 : format.integerRequired; - decimalSymbol = format.decimalSymbol === undefined ? ',' : format.decimalSymbol; + decimalSymbol = format.decimalSymbol === undefined ? '.' : format.decimalSymbol; groupSymbol = format.groupSymbol === undefined ? '.' : format.groupSymbol; groupLength = format.groupLength === undefined ? 3 : format.groupLength; pattern = format.pattern || '%s'; diff --git a/app/code/Magento/Directory/Model/PriceCurrency.php b/app/code/Magento/Directory/Model/PriceCurrency.php index 4c24c2016c51a..4f901454ebb40 100644 --- a/app/code/Magento/Directory/Model/PriceCurrency.php +++ b/app/code/Magento/Directory/Model/PriceCurrency.php @@ -152,9 +152,8 @@ protected function getStore($scope = null) */ public function round($price) { - return round((float) $price, 2); + return round((float) $price, self::DEFAULT_PRECISION); } - /** * Round price with precision * diff --git a/app/code/Magento/Quote/Model/Quote/Item/AbstractItem.php b/app/code/Magento/Quote/Model/Quote/Item/AbstractItem.php index 058411abe720b..e8dcd51c13f2b 100644 --- a/app/code/Magento/Quote/Model/Quote/Item/AbstractItem.php +++ b/app/code/Magento/Quote/Model/Quote/Item/AbstractItem.php @@ -409,7 +409,6 @@ public function calcRowTotal() // Round unit price before multiplying to prevent losing 1 cent on subtotal $total = $this->priceCurrency->round($this->getCalculationPriceOriginal()) * $qty; $baseTotal = $this->priceCurrency->round($this->getBaseCalculationPriceOriginal()) * $qty; - $this->setRowTotal($this->priceCurrency->round($total)); $this->setBaseRowTotal($this->priceCurrency->round($baseTotal)); return $this; @@ -582,6 +581,7 @@ public function setPrice($value) */ public function getConvertedPrice() { + $price = $this->_getData('converted_price'); if ($price === null) { $price = $this->priceCurrency->convert($this->getPrice(), $this->getStore()); diff --git a/lib/internal/Magento/Framework/Pricing/PriceCurrencyInterface.php b/lib/internal/Magento/Framework/Pricing/PriceCurrencyInterface.php index aea2aacef5edf..0a86dd0e6230d 100644 --- a/lib/internal/Magento/Framework/Pricing/PriceCurrencyInterface.php +++ b/lib/internal/Magento/Framework/Pricing/PriceCurrencyInterface.php @@ -14,7 +14,7 @@ */ interface PriceCurrencyInterface { - const DEFAULT_PRECISION = 2; + const DEFAULT_PRECISION = 4; /** * Convert price value From 05cfe7a3a755cb350e51174461217b7f810c0af7 Mon Sep 17 00:00:00 2001 From: Jetty Rohan Aditya Date: Thu, 31 Aug 2023 12:25:21 +0530 Subject: [PATCH 2/2] Changed the precison condition --- app/code/Magento/Catalog/view/base/web/js/price-utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/view/base/web/js/price-utils.js b/app/code/Magento/Catalog/view/base/web/js/price-utils.js index 5233d6493f6d2..32dcfb8d861bc 100644 --- a/app/code/Magento/Catalog/view/base/web/js/price-utils.js +++ b/app/code/Magento/Catalog/view/base/web/js/price-utils.js @@ -41,7 +41,7 @@ define([ var s = '', precision, pattern, locale, r; format = _.extend(globalPriceFormat, format); - precision = !isNaN(format.requiredPrecision = Math.abs(format.requiredPrecision)) ? 4 : format.requiredPrecision; + precision = !isNaN(format.requiredPrecision = Math.abs(format.requiredPrecision)) ? format.requiredPrecision : 4; pattern = format.pattern || '%s'; locale = window.LOCALE || 'en-US'; if (isShowSign === undefined || isShowSign === true) {