Skip to content

Commit 401807e

Browse files
committed
ACP2E-3658: Admin displays incorrect currency symbol on when creating return
1 parent 727294d commit 401807e

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Currency.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Backend\Block\Widget\Grid\Column\Renderer;
88

9+
use Magento\Framework\Exception\NoSuchEntityException;
10+
911
/**
1012
* Backend grid item renderer currency
1113
*
@@ -108,6 +110,25 @@ protected function _getCurrencyCode($row)
108110
return $code;
109111
}
110112

113+
$storeId = $row->getData('store_id');
114+
if ($storeId) {
115+
try {
116+
$store = $this->_storeManager->getStore($storeId);
117+
// Check if the currency is set at the store level
118+
$currencyCode = $store->getCurrentCurrencyCode();
119+
if ($currencyCode) {
120+
return $currencyCode;
121+
}
122+
$website = $store->getWebsite();
123+
// Check if the currency is set at the website level
124+
$currencyCode = $website->getBaseCurrencyCode();
125+
if ($currencyCode) {
126+
return $currencyCode;
127+
}
128+
} catch (NoSuchEntityException $e) {
129+
$this->_logger->warning('Failed to get website currency: ' . $e->getMessage());
130+
}
131+
}
111132
return $this->_currencyLocator->getDefaultCurrency($this->_request);
112133
}
113134

app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/Column/Renderer/CurrencyTest.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -16,7 +16,9 @@
1616
use Magento\Framework\DataObject;
1717
use Magento\Framework\Locale\CurrencyInterface;
1818
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
19+
use Magento\Store\Model\Store;
1920
use Magento\Store\Model\StoreManagerInterface;
21+
use Magento\Store\Model\Website;
2022
use PHPUnit\Framework\MockObject\MockObject;
2123
use PHPUnit\Framework\TestCase;
2224

@@ -138,4 +140,42 @@ public function testRenderWithDefaultCurrency()
138140

139141
$this->assertEquals('15USD', $this->_blockCurrency->render($this->_row));
140142
}
143+
144+
/**
145+
* @covers \Magento\Backend\Block\Widget\Grid\Column\Renderer\Currency::render
146+
*/
147+
public function testRenderWithNonDefaultCurrency()
148+
{
149+
$this->_currencyMock->expects($this->once())
150+
->method('getRate')
151+
->with('nonDefaultCurrency')
152+
->willReturn(2.0);
153+
$this->_curLocatorMock->expects($this->never())
154+
->method('getDefaultCurrency');
155+
$currLocaleMock = $this->createMock(CurrencyData::class);
156+
$currLocaleMock->expects($this->once())
157+
->method('toCurrency')
158+
->with(20.0000)
159+
->willReturn('20EUR');
160+
$this->_localeMock->expects($this->once())
161+
->method('getCurrency')
162+
->with('nonDefaultCurrency')
163+
->willReturn($currLocaleMock);
164+
$this->_columnMock->method('getCurrency')->willReturn('EUR');
165+
$this->_columnMock->method('getRateField')->willReturn('test_rate_field');
166+
$this->_row->setData('store_id', 1);
167+
$storeMock = $this->createMock(Store::class);
168+
$websiteMock = $this->createMock(Website::class);
169+
$websiteMock->expects($this->exactly(2))
170+
->method('getBaseCurrencyCode')
171+
->willReturn('nonDefaultCurrency');
172+
$storeMock->expects($this->exactly(2))
173+
->method('getWebsite')
174+
->willReturn($websiteMock);
175+
$this->_storeManagerMock->expects($this->exactly(2))
176+
->method('getStore')
177+
->with(1)
178+
->willReturn($storeMock);
179+
$this->assertEquals('20EUR', $this->_blockCurrency->render($this->_row));
180+
}
141181
}

0 commit comments

Comments
 (0)