@@ -77,8 +77,7 @@ public function format(
77
77
$ scope = null ,
78
78
$ currency = null
79
79
) {
80
- return $ this ->getCurrency ($ scope , $ currency )
81
- ->formatPrecision ($ amount , $ precision , [], $ includeContainer );
80
+ return $ this ->createCurrency ($ scope , $ currency )->formatPrecision ($ amount , $ precision , [], $ includeContainer );
82
81
}
83
82
84
83
/**
@@ -101,20 +100,7 @@ public function convertAndFormat(
101
100
*/
102
101
public function getCurrency ($ scope = null , $ currency = null )
103
102
{
104
- if ($ currency instanceof Currency) {
105
- $ currentCurrency = $ currency ;
106
- } elseif (is_string ($ currency )) {
107
- $ currency = $ this ->currencyFactory ->create ()
108
- ->load ($ currency );
109
- $ baseCurrency = $ this ->getStore ($ scope )
110
- ->getBaseCurrency ();
111
- $ currentCurrency = $ baseCurrency ->getRate ($ currency ) ? $ currency : $ baseCurrency ;
112
- } else {
113
- $ currentCurrency = $ this ->getStore ($ scope )
114
- ->getCurrentCurrency ();
115
- }
116
-
117
- return $ currentCurrency ;
103
+ return $ this ->createCurrency ($ scope , $ currency , true );
118
104
}
119
105
120
106
/**
@@ -157,4 +143,30 @@ public function round($price)
157
143
{
158
144
return round ($ price , 2 );
159
145
}
146
+
147
+ /**
148
+ * Get currency considering currency rate configuration.
149
+ *
150
+ * @param null|string|bool|int|\Magento\Framework\App\ScopeInterface $scope
151
+ * @param \Magento\Framework\Model\AbstractModel|string|null $currency
152
+ * @param bool $includeRate
153
+ *
154
+ * @return Currency
155
+ */
156
+ private function createCurrency ($ scope , $ currency , bool $ includeRate = false )
157
+ {
158
+ if ($ currency instanceof Currency) {
159
+ $ currentCurrency = $ currency ;
160
+ } elseif (is_string ($ currency )) {
161
+ $ currentCurrency = $ this ->currencyFactory ->create ()->load ($ currency );
162
+ if ($ includeRate ) {
163
+ $ baseCurrency = $ this ->getStore ($ scope )->getBaseCurrency ();
164
+ $ currentCurrency = $ baseCurrency ->getRate ($ currentCurrency ) ? $ currentCurrency : $ baseCurrency ;
165
+ }
166
+ } else {
167
+ $ currentCurrency = $ this ->getStore ($ scope )->getCurrentCurrency ();
168
+ }
169
+
170
+ return $ currentCurrency ;
171
+ }
160
172
}
0 commit comments