Skip to content

Commit 8a28683

Browse files
committed
ACP2E-3276: Order reports showing the wrong currency symbol
1 parent 2395a8c commit 8a28683

File tree

2 files changed

+5
-202
lines changed

2 files changed

+5
-202
lines changed

app/code/Magento/Directory/Model/Currency/DefaultLocator.php

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
namespace Magento\Directory\Model\Currency;
77

8-
use Magento\Store\Model\Store;
98

109
class DefaultLocator
1110
{
@@ -17,7 +16,7 @@ class DefaultLocator
1716
protected $_configuration;
1817

1918
/**
20-
* Store manager model
19+
* Store manager
2120
*
2221
* @var \Magento\Store\Model\StoreManagerInterface
2322
*/
@@ -37,9 +36,7 @@ public function __construct(
3736

3837
/**
3938
* Retrieve default currency for selected store, website or website group
40-
*
4139
* @todo: Refactor to ScopeDefiner
42-
*
4340
* @param \Magento\Framework\App\RequestInterface $request
4441
* @return string
4542
*/
@@ -67,57 +64,4 @@ public function getDefaultCurrency(\Magento\Framework\App\RequestInterface $requ
6764

6865
return $currencyCode;
6966
}
70-
71-
/**
72-
* Retrieve display currency for selected store, website or website group
73-
*
74-
* @param \Magento\Framework\App\RequestInterface $request
75-
* @return string
76-
*/
77-
public function getDisplayCurrency(\Magento\Framework\App\RequestInterface $request): string
78-
{
79-
if ($request->getParam('store')) {
80-
$store = $request->getParam('store');
81-
$currencyCode = $this->_storeManager->getStore($store)->getDefaultCurrencyCode();
82-
} else {
83-
if ($request->getParam('website')) {
84-
$website = $request->getParam('website');
85-
$currencyCode = $this->getDefaultCurrencyCode($website);
86-
} else {
87-
if ($request->getParam('group')) {
88-
$group = $request->getParam('group');
89-
$currencyCode = $this->_storeManager->getGroup($group)->getWebsite()->getDefaultCurrencyCode();
90-
} else {
91-
$currencyCode = $this->_configuration->getValue(
92-
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_DEFAULT,
93-
'default'
94-
);
95-
}
96-
}
97-
}
98-
99-
return $currencyCode;
100-
}
101-
102-
/**
103-
* Retrieve website default currency code
104-
*
105-
* @param string $website
106-
* @return string
107-
*/
108-
private function getDefaultCurrencyCode($website): string
109-
{
110-
$website = $this->_storeManager->getWebsite($website);
111-
$priceScope = $website->getConfig(Store::XML_PATH_PRICE_SCOPE);
112-
if ($priceScope == Store::PRICE_SCOPE_GLOBAL) {
113-
$currencyCode = $this->_configuration->getValue(
114-
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_DEFAULT,
115-
'default'
116-
);
117-
} else {
118-
$currencyCode = $website->getConfig(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_DEFAULT);
119-
}
120-
121-
return $currencyCode;
122-
}
12367
}

app/code/Magento/Reports/Block/Adminhtml/Grid/Column/Renderer/Currency.php

Lines changed: 4 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -7,178 +7,37 @@
77

88
namespace Magento\Reports\Block\Adminhtml\Grid\Column\Renderer;
99

10-
use Magento\Backend\Block\Context;
1110
use Magento\Backend\Block\Widget\Grid\Column\Renderer\Currency as BackendCurrency;
12-
use Magento\Directory\Model\Currency\DefaultLocator;
13-
use Magento\Directory\Model\CurrencyFactory;
1411
use Magento\Framework\Currency\Exception\CurrencyException;
1512
use Magento\Framework\DataObject;
16-
use Magento\Framework\Exception\LocalizedException;
17-
use Magento\Framework\Exception\NoSuchEntityException;
18-
use Magento\Framework\Locale\CurrencyInterface;
19-
use Magento\Store\Model\ScopeInterface;
20-
use Magento\Store\Model\Store;
21-
use Magento\Store\Model\StoreManagerInterface;
2213

2314
/**
2415
* Adminhtml grid item renderer currency
2516
*
2617
* @api
2718
* @since 100.0.2
2819
*
29-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3020
*/
3121
class Currency extends BackendCurrency
3222
{
33-
/**
34-
* @var CurrencyFactory
35-
*/
36-
private $currencyFactory;
37-
38-
/**
39-
* @param Context $context
40-
* @param StoreManagerInterface $storeManager
41-
* @param DefaultLocator $currencyLocator
42-
* @param CurrencyFactory $currencyFactory
43-
* @param CurrencyInterface $localeCurrency
44-
* @param array $data
45-
*/
46-
public function __construct(
47-
Context $context,
48-
StoreManagerInterface $storeManager,
49-
DefaultLocator $currencyLocator,
50-
CurrencyFactory $currencyFactory,
51-
CurrencyInterface $localeCurrency,
52-
array $data = []
53-
) {
54-
parent::__construct(
55-
$context,
56-
$storeManager,
57-
$currencyLocator,
58-
$currencyFactory,
59-
$localeCurrency,
60-
$data
61-
);
62-
$this->currencyFactory = $currencyFactory;
63-
}
64-
6523
/**
6624
* Renders grid column
6725
*
6826
* @param DataObject $row
6927
* @return string
70-
* @throws LocalizedException
71-
* @throws NoSuchEntityException
7228
* @throws CurrencyException
7329
*/
7430
public function render(DataObject $row)
7531
{
7632
$data = $row->getData($this->getColumn()->getIndex());
77-
$currencyCode = $this->getStoreCurrencyCode($row);
33+
$currencyCode = $this->_getCurrencyCode($row);
7834

7935
if (!$currencyCode) {
8036
return $data;
8137
}
82-
$rate = $this->getStoreCurrencyRate($currencyCode, $row);
83-
$data = (float) $data * $rate;
38+
$data = (float)$data * $this->_getRate($row);
8439
$data = sprintf('%f', $data);
85-
$displayCurrencyCode = $this->getStoreDisplayCurrencyCode($row);
86-
return $this->_localeCurrency->getCurrency($displayCurrencyCode)->toCurrency($data);
87-
}
88-
89-
/**
90-
* Get admin currency code
91-
*
92-
* @return string
93-
* @throws LocalizedException
94-
* @throws NoSuchEntityException
95-
*/
96-
private function getAdminCurrencyCode(): string
97-
{
98-
$adminWebsiteId = (int) $this->_storeManager
99-
->getStore(Store::ADMIN_CODE)
100-
->getWebsiteId();
101-
return (string) $this->_storeManager
102-
->getWebsite($adminWebsiteId)
103-
->getBaseCurrencyCode();
104-
}
105-
106-
/**
107-
* Get store currency code
108-
*
109-
* @param DataObject $row
110-
* @return string
111-
* @throws NoSuchEntityException
112-
*/
113-
private function getStoreCurrencyCode(DataObject $row): string
114-
{
115-
$catalogPriceScope = $this->getCatalogPriceScope();
116-
$storeId = $this->_request->getParam('store_ids');
117-
if ($catalogPriceScope != 0 && !empty($storeId)) {
118-
$currencyCode = $this->_storeManager->getStore($storeId)->getBaseCurrencyCode();
119-
} elseif ($catalogPriceScope != 0) {
120-
$currencyCode = $this->_currencyLocator->getDefaultCurrency($this->_request);
121-
} else {
122-
$currencyCode = $this->_getCurrencyCode($row);
123-
}
124-
return $currencyCode;
125-
}
126-
127-
/**
128-
* Get store display currency code
129-
*
130-
* @param DataObject $row
131-
* @return string
132-
* @throws NoSuchEntityException
133-
*/
134-
private function getStoreDisplayCurrencyCode(DataObject $row): string
135-
{
136-
$catalogPriceScope = $this->getCatalogPriceScope();
137-
$storeId = $this->_request->getParam('store_ids');
138-
if ($catalogPriceScope != 0 && !empty($storeId)) {
139-
$currencyCode = $this->_storeManager->getStore($storeId)->getDefaultCurrencyCode();
140-
} elseif ($catalogPriceScope != 0) {
141-
$currencyCode = $this->_currencyLocator->getDisplayCurrency($this->_request);
142-
} else {
143-
$currencyCode = $this->_getCurrencyCode($row);
144-
}
145-
return $currencyCode;
146-
}
147-
148-
/**
149-
* Get store currency rate
150-
*
151-
* @param string $currencyCode
152-
* @param DataObject $row
153-
* @return float
154-
* @throws LocalizedException
155-
* @throws NoSuchEntityException
156-
*/
157-
private function getStoreCurrencyRate(string $currencyCode, DataObject $row): float
158-
{
159-
$catalogPriceScope = $this->getCatalogPriceScope();
160-
$adminCurrencyCode = $this->getAdminCurrencyCode();
161-
162-
if (((int)$catalogPriceScope !== 0
163-
&& $adminCurrencyCode !== $currencyCode)) {
164-
$currency = $this->currencyFactory->create()->load($adminCurrencyCode);
165-
$currencyRate = $currency->getAnyRate($currencyCode);
166-
} else {
167-
$currencyRate = $this->_getRate($row);
168-
}
169-
return (float) $currencyRate;
170-
}
171-
172-
/**
173-
* Get catalog price scope from the admin config
174-
*
175-
* @return int
176-
*/
177-
private function getCatalogPriceScope(): int
178-
{
179-
return (int) $this->_scopeConfig->getValue(
180-
Store::XML_PATH_PRICE_SCOPE,
181-
ScopeInterface::SCOPE_WEBSITE
182-
);
40+
$data = $this->_localeCurrency->getCurrency($currencyCode)->toCurrency($data);
41+
return $data;
18342
}
18443
}

0 commit comments

Comments
 (0)