|
7 | 7 |
|
8 | 8 | namespace Magento\Reports\Block\Adminhtml\Grid\Column\Renderer; |
9 | 9 |
|
10 | | -use Magento\Backend\Block\Context; |
11 | 10 | use Magento\Backend\Block\Widget\Grid\Column\Renderer\Currency as BackendCurrency; |
12 | | -use Magento\Directory\Model\Currency\DefaultLocator; |
13 | | -use Magento\Directory\Model\CurrencyFactory; |
14 | 11 | use Magento\Framework\Currency\Exception\CurrencyException; |
15 | 12 | 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; |
22 | 13 |
|
23 | 14 | /** |
24 | 15 | * Adminhtml grid item renderer currency |
25 | 16 | * |
26 | | - * @author Magento Core Team <core@magentocommerce.com> |
27 | 17 | * @api |
28 | 18 | * @since 100.0.2 |
29 | 19 | * |
30 | | - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
31 | 20 | */ |
32 | 21 | class Currency extends BackendCurrency |
33 | 22 | { |
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 | | - |
66 | 23 | /** |
67 | 24 | * Renders grid column |
68 | 25 | * |
69 | 26 | * @param DataObject $row |
70 | 27 | * @return string |
71 | | - * @throws LocalizedException |
72 | | - * @throws NoSuchEntityException |
73 | 28 | * @throws CurrencyException |
74 | 29 | */ |
75 | 30 | public function render(DataObject $row) |
76 | 31 | { |
77 | 32 | $data = $row->getData($this->getColumn()->getIndex()); |
78 | | - $currencyCode = $this->getStoreCurrencyCode($row); |
| 33 | + $currencyCode = $this->_getCurrencyCode($row); |
79 | 34 |
|
80 | 35 | if (!$currencyCode) { |
81 | 36 | return $data; |
82 | 37 | } |
83 | | - $rate = $this->getStoreCurrencyRate($currencyCode, $row); |
84 | | - $data = (float) $data * $rate; |
| 38 | + $data = (float)$data * $this->_getRate($row); |
85 | 39 | $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; |
162 | 42 | } |
163 | 43 | } |
0 commit comments