Skip to content

Commit 681a15c

Browse files
committed
Merge remote-tracking branch 'adobe-commerce-tier-4/ACP2E-3276' into Tier4-Kings-PR-10-14-2024
2 parents eb662db + 402ab7b commit 681a15c

File tree

5 files changed

+251
-451
lines changed

5 files changed

+251
-451
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Directory\Test\Fixture;
9+
10+
use Magento\Directory\Model\Currency;
11+
use Magento\Framework\App\ResourceConnection;
12+
use Magento\Framework\DataObject;
13+
use Magento\Framework\Locale\FormatInterface;
14+
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
15+
16+
/**
17+
* Data fixture for currency rate.
18+
*/
19+
class CurrencyRate implements RevertibleDataFixtureInterface
20+
{
21+
/**
22+
* @var FormatInterface
23+
*/
24+
private $format;
25+
26+
/**
27+
* @var Currency
28+
*/
29+
private $currency;
30+
31+
/**
32+
* @var ResourceConnection
33+
*/
34+
private $resourceConnection;
35+
36+
public function __construct(
37+
FormatInterface $format,
38+
Currency $currency,
39+
ResourceConnection $resourceConnection
40+
) {
41+
$this->format = $format;
42+
$this->currency = $currency;
43+
$this->resourceConnection = $resourceConnection;
44+
}
45+
46+
public function apply(array $data = []): ?DataObject
47+
{
48+
foreach ($data as $currencyCode => $rate) {
49+
foreach ($rate as $currencyTo => $value) {
50+
$value = abs((float) $this->format->getNumber($value));
51+
$data[$currencyCode][$currencyTo] = $value;
52+
}
53+
}
54+
55+
return $this->currency->saveRates($data);
56+
}
57+
58+
public function revert(DataObject $data): void
59+
{
60+
$connection = $this->resourceConnection->getConnection();
61+
$currencyTable = $this->resourceConnection->getTableName('directory_currency_rate');
62+
63+
foreach ($data as $currencyCode => $rate) {
64+
foreach ($rate as $currencyTo) {
65+
$connection->delete(
66+
$currencyTable,
67+
[
68+
'currency_from = ?' => $currencyCode,
69+
'currency_to = ?' => $currencyTo,
70+
]
71+
);
72+
}
73+
}
74+
}
75+
}

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

Lines changed: 4 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -7,157 +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
*
26-
* @author Magento Core Team <core@magentocommerce.com>
2717
* @api
2818
* @since 100.0.2
2919
*
30-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3120
*/
3221
class Currency extends BackendCurrency
3322
{
34-
/**
35-
* @var CurrencyFactory
36-
*/
37-
private $currencyFactory;
38-
39-
/**
40-
* @param Context $context
41-
* @param StoreManagerInterface $storeManager
42-
* @param DefaultLocator $currencyLocator
43-
* @param CurrencyFactory $currencyFactory
44-
* @param CurrencyInterface $localeCurrency
45-
* @param array $data
46-
*/
47-
public function __construct(
48-
Context $context,
49-
StoreManagerInterface $storeManager,
50-
DefaultLocator $currencyLocator,
51-
CurrencyFactory $currencyFactory,
52-
CurrencyInterface $localeCurrency,
53-
array $data = []
54-
) {
55-
parent::__construct(
56-
$context,
57-
$storeManager,
58-
$currencyLocator,
59-
$currencyFactory,
60-
$localeCurrency,
61-
$data
62-
);
63-
$this->currencyFactory = $currencyFactory;
64-
}
65-
6623
/**
6724
* Renders grid column
6825
*
6926
* @param DataObject $row
7027
* @return string
71-
* @throws LocalizedException
72-
* @throws NoSuchEntityException
7328
* @throws CurrencyException
7429
*/
7530
public function render(DataObject $row)
7631
{
7732
$data = $row->getData($this->getColumn()->getIndex());
78-
$currencyCode = $this->getStoreCurrencyCode($row);
33+
$currencyCode = $this->_getCurrencyCode($row);
7934

8035
if (!$currencyCode) {
8136
return $data;
8237
}
83-
$rate = $this->getStoreCurrencyRate($currencyCode, $row);
84-
$data = (float) $data * $rate;
38+
$data = (float)$data * $this->_getRate($row);
8539
$data = sprintf('%f', $data);
86-
return $this->_localeCurrency->getCurrency($currencyCode)->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 currency rate
129-
*
130-
* @param string $currencyCode
131-
* @param DataObject $row
132-
* @return float
133-
* @throws LocalizedException
134-
* @throws NoSuchEntityException
135-
*/
136-
private function getStoreCurrencyRate(string $currencyCode, DataObject $row): float
137-
{
138-
$catalogPriceScope = $this->getCatalogPriceScope();
139-
$adminCurrencyCode = $this->getAdminCurrencyCode();
140-
141-
if (((int)$catalogPriceScope !== 0
142-
&& $adminCurrencyCode !== $currencyCode)) {
143-
$currency = $this->currencyFactory->create()->load($adminCurrencyCode);
144-
$currencyRate = $currency->getAnyRate($currencyCode);
145-
} else {
146-
$currencyRate = $this->_getRate($row);
147-
}
148-
return (float) $currencyRate;
149-
}
150-
151-
/**
152-
* Get catalog price scope from the admin config
153-
*
154-
* @return int
155-
*/
156-
private function getCatalogPriceScope(): int
157-
{
158-
return (int) $this->_scopeConfig->getValue(
159-
Store::XML_PATH_PRICE_SCOPE,
160-
ScopeInterface::SCOPE_WEBSITE
161-
);
40+
$data = $this->_localeCurrency->getCurrency($currencyCode)->toCurrency($data);
41+
return $data;
16242
}
16343
}

0 commit comments

Comments
 (0)