Skip to content

Commit eccaa4a

Browse files
ENGCOM-3688: Cleaned up PriceCurrency class #19222
- Merge Pull Request #19222 from creaminternet/magento2-opensource:Cleanup-PriceCurrency - Merged commits: 1. 252b199 2. 7e9eb99 3. a7df0f0 4. be6082f
2 parents b8892f0 + be6082f commit eccaa4a

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

app/code/Magento/Directory/Model/PriceCurrency.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct(
4646
}
4747

4848
/**
49-
* {@inheritdoc}
49+
* @inheritdoc
5050
*/
5151
public function convert($amount, $scope = null, $currency = null)
5252
{
@@ -58,17 +58,15 @@ public function convert($amount, $scope = null, $currency = null)
5858
}
5959

6060
/**
61-
* {@inheritdoc}
61+
* @inheritdoc
6262
*/
6363
public function convertAndRound($amount, $scope = null, $currency = null, $precision = self::DEFAULT_PRECISION)
6464
{
65-
$currentCurrency = $this->getCurrency($scope, $currency);
66-
$convertedValue = $this->getStore($scope)->getBaseCurrency()->convert($amount, $currentCurrency);
67-
return round($convertedValue, $precision);
65+
return $this->roundPrice($this->convert($amount, $scope, $currency), $precision);
6866
}
6967

7068
/**
71-
* {@inheritdoc}
69+
* @inheritdoc
7270
*/
7371
public function format(
7472
$amount,
@@ -82,7 +80,7 @@ public function format(
8280
}
8381

8482
/**
85-
* {@inheritdoc}
83+
* @inheritdoc
8684
*/
8785
public function convertAndFormat(
8886
$amount,
@@ -97,7 +95,7 @@ public function convertAndFormat(
9795
}
9896

9997
/**
100-
* {@inheritdoc}
98+
* @inheritdoc
10199
*/
102100
public function getCurrency($scope = null, $currency = null)
103101
{
@@ -148,13 +146,22 @@ protected function getStore($scope = null)
148146
}
149147

150148
/**
151-
* Round price
149+
* @inheritdoc
150+
*/
151+
public function round($price)
152+
{
153+
return round($price, 2);
154+
}
155+
156+
/**
157+
* Round price with precision
152158
*
153159
* @param float $price
160+
* @param int $precision
154161
* @return float
155162
*/
156-
public function round($price)
163+
public function roundPrice($price, $precision = self::DEFAULT_PRECISION)
157164
{
158-
return round($price, 2);
165+
return round($price, $precision);
159166
}
160167
}

lib/internal/Magento/Framework/Pricing/PriceCurrencyInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function convertAndFormat(
7878
/**
7979
* Round price
8080
*
81+
* @deprecated
8182
* @param float $price
8283
* @return float
8384
*/

0 commit comments

Comments
 (0)