@@ -77,15 +77,7 @@ public function format(
77
77
$ scope = null ,
78
78
$ currency = null
79
79
) {
80
- if ($ currency instanceof Currency) {
81
- $ currentCurrency = $ currency ;
82
- } elseif (is_string ($ currency )) {
83
- $ currentCurrency = $ this ->currencyFactory ->create ()->load ($ currency );
84
- } else {
85
- $ currentCurrency = $ this ->getStore ($ scope )->getCurrentCurrency ();
86
- }
87
-
88
- return $ currentCurrency ->formatPrecision ($ amount , $ precision , [], $ includeContainer );
80
+ return $ this ->createCurrency ($ scope , $ currency )->formatPrecision ($ amount , $ precision , [], $ includeContainer );
89
81
}
90
82
91
83
/**
@@ -108,20 +100,7 @@ public function convertAndFormat(
108
100
*/
109
101
public function getCurrency ($ scope = null , $ currency = null )
110
102
{
111
- if ($ currency instanceof Currency) {
112
- $ currentCurrency = $ currency ;
113
- } elseif (is_string ($ currency )) {
114
- $ currency = $ this ->currencyFactory ->create ()
115
- ->load ($ currency );
116
- $ baseCurrency = $ this ->getStore ($ scope )
117
- ->getBaseCurrency ();
118
- $ currentCurrency = $ baseCurrency ->getRate ($ currency ) ? $ currency : $ baseCurrency ;
119
- } else {
120
- $ currentCurrency = $ this ->getStore ($ scope )
121
- ->getCurrentCurrency ();
122
- }
123
-
124
- return $ currentCurrency ;
103
+ return $ this ->createCurrency ($ scope , $ currency , true );
125
104
}
126
105
127
106
/**
@@ -164,4 +143,30 @@ public function round($price)
164
143
{
165
144
return round ($ price , 2 );
166
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
+ }
167
172
}
0 commit comments