Skip to content

Commit af8443c

Browse files
committed
MC-23915: Wrong currency symbol in creditmemo_grid & sales_order_view > creditmemo grid for subtotal & Shipping and Handling fee
1 parent 427f9bf commit af8443c

File tree

4 files changed

+82
-14
lines changed

4 files changed

+82
-14
lines changed

app/code/Magento/Sales/Test/Unit/Ui/Component/Listing/Column/PurchasedPriceTest.php

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1212
use Magento\Framework\View\Element\UiComponent\ContextInterface;
1313
use Magento\Framework\View\Element\UiComponent\Processor;
14+
use Magento\Sales\Api\OrderRepositoryInterface;
1415
use Magento\Sales\Ui\Component\Listing\Column\Price;
1516
use Magento\Sales\Ui\Component\Listing\Column\PurchasedPrice;
1617
use PHPUnit\Framework\MockObject\MockObject;
@@ -28,6 +29,11 @@ class PurchasedPriceTest extends TestCase
2829
*/
2930
protected $currencyMock;
3031

32+
/**
33+
* @var OrderRepositoryInterface|MockObject
34+
*/
35+
protected $orderMock;
36+
3137
protected function setUp(): void
3238
{
3339
$objectManager = new ObjectManager($this);
@@ -41,31 +47,60 @@ protected function setUp(): void
4147
->setMethods(['load', 'format'])
4248
->disableOriginalConstructor()
4349
->getMock();
50+
$this->orderMock = $this->getMockBuilder(OrderRepositoryInterface::class)
51+
->setMethods(['getList','get','delete','save','getOrderCurrencyCode'])
52+
->disableOriginalConstructor()
53+
->getMock();
4454
$this->model = $objectManager->getObject(
4555
PurchasedPrice::class,
46-
['currency' => $this->currencyMock, 'context' => $contextMock]
56+
[
57+
'currency' => $this->currencyMock,
58+
'context' => $contextMock,
59+
'order' => $this->orderMock,
60+
]
4761
);
4862
}
4963

50-
public function testPrepareDataSource()
51-
{
52-
$itemName = 'itemName';
53-
$oldItemValue = 'oldItemValue';
54-
$newItemValue = 'newItemValue';
64+
/**
65+
* @param string $itemName
66+
* @param string $oldItemValue
67+
* @param string $newItemValue
68+
* @param string|null $orderCurrencyCode
69+
* @dataProvider prepareDataSourceDataProvider
70+
*/
71+
public function testPrepareDataSource(
72+
$itemName,
73+
$oldItemValue,
74+
$newItemValue,
75+
$orderCurrencyCode
76+
): void {
5577
$dataSource = [
5678
'data' => [
5779
'items' => [
5880
[
5981
$itemName => $oldItemValue,
60-
'order_currency_code' => 'US'
82+
'order_currency_code' => $orderCurrencyCode,
83+
'order_id' => 1,
6184
]
6285
]
6386
]
6487
];
6588

89+
if (isset($dataSource['data']['items'][0]['order_currency_code'])) {
90+
$currencyCode = $dataSource['data']['items'][0]['order_currency_code'];
91+
} else {
92+
$currencyCode = 'FR';
93+
$this->orderMock->expects($this->once())
94+
->method('get')
95+
->willReturnSelf();
96+
$this->orderMock->expects($this->once())
97+
->method('getOrderCurrencyCode')
98+
->willReturn($currencyCode);
99+
}
100+
66101
$this->currencyMock->expects($this->once())
67102
->method('load')
68-
->with($dataSource['data']['items'][0]['order_currency_code'])
103+
->with($currencyCode)
69104
->willReturnSelf();
70105

71106
$this->currencyMock->expects($this->once())
@@ -77,4 +112,25 @@ public function testPrepareDataSource()
77112
$dataSource = $this->model->prepareDataSource($dataSource);
78113
$this->assertEquals($newItemValue, $dataSource['data']['items'][0][$itemName]);
79114
}
115+
116+
/**
117+
* @return array
118+
*/
119+
public function prepareDataSourceDataProvider(): array
120+
{
121+
return [
122+
[
123+
'item_name' => 'itemName',
124+
'old_item_value' => 'oldItemValue',
125+
'new_item_value' => 'newItemValue',
126+
'order_currency_code' => 'US',
127+
],
128+
[
129+
'item_name' => 'itemName',
130+
'old_item_value' => 'oldItemValue',
131+
'new_item_value' => 'newItemValue',
132+
'order_currency_code' => null,
133+
],
134+
];
135+
}
80136
}

app/code/Magento/Sales/Ui/Component/Listing/Column/PurchasedPrice.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Framework\View\Element\UiComponent\ContextInterface;
1111
use Magento\Framework\View\Element\UiComponentFactory;
12+
use Magento\Sales\Api\OrderRepositoryInterface;
1213
use Magento\Ui\Component\Listing\Columns\Column;
1314
use Magento\Framework\Pricing\PriceCurrencyInterface;
1415
use Magento\Directory\Model\Currency;
@@ -28,6 +29,11 @@ class PurchasedPrice extends Column
2829
*/
2930
private $currency;
3031

32+
/**
33+
* @var OrderRepositoryInterface
34+
*/
35+
private $order;
36+
3137
/**
3238
* Constructor
3339
*
@@ -37,18 +43,22 @@ class PurchasedPrice extends Column
3743
* @param array $components
3844
* @param array $data
3945
* @param Currency $currency
46+
* @param OrderRepositoryInterface $order
4047
*/
4148
public function __construct(
4249
ContextInterface $context,
4350
UiComponentFactory $uiComponentFactory,
4451
PriceCurrencyInterface $priceFormatter,
4552
array $components = [],
4653
array $data = [],
47-
Currency $currency = null
54+
Currency $currency = null,
55+
OrderRepositoryInterface $order = null
4856
) {
4957
$this->priceFormatter = $priceFormatter;
5058
$this->currency = $currency ?: \Magento\Framework\App\ObjectManager::getInstance()
5159
->create(Currency::class);
60+
$this->order = $order ?: \Magento\Framework\App\ObjectManager::getInstance()
61+
->create(OrderRepositoryInterface::class);
5262
parent::__construct($context, $uiComponentFactory, $components, $data);
5363
}
5464

@@ -62,7 +72,9 @@ public function prepareDataSource(array $dataSource)
6272
{
6373
if (isset($dataSource['data']['items'])) {
6474
foreach ($dataSource['data']['items'] as & $item) {
65-
$currencyCode = isset($item['order_currency_code']) ? $item['order_currency_code'] : null;
75+
$currencyCode = isset($item['order_currency_code'])
76+
? $item['order_currency_code']
77+
: $this->order->get($item['order_id'])->getOrderCurrencyCode();
6678
$purchaseCurrency = $this->currency->load($currencyCode);
6779
$item[$this->getData('name')] = $purchaseCurrency
6880
->format($item[$this->getData('name')], [], false);

app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_creditmemo_grid.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@
194194
<visible>false</visible>
195195
</settings>
196196
</column>
197-
<column name="subtotal" class="Magento\Sales\Ui\Component\Listing\Column\Price">
197+
<column name="subtotal" class="Magento\Sales\Ui\Component\Listing\Column\PurchasedPrice">
198198
<settings>
199199
<filter>textRange</filter>
200200
<label translate="true">Subtotal</label>
201201
<visible>false</visible>
202202
</settings>
203203
</column>
204-
<column name="shipping_and_handling" class="Magento\Sales\Ui\Component\Listing\Column\Price">
204+
<column name="shipping_and_handling" class="Magento\Sales\Ui\Component\Listing\Column\PurchasedPrice">
205205
<settings>
206206
<filter>textRange</filter>
207207
<label translate="true">Shipping &amp; Handling</label>

app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_creditmemo_grid.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,14 @@
207207
<visible>false</visible>
208208
</settings>
209209
</column>
210-
<column name="subtotal" class="Magento\Sales\Ui\Component\Listing\Column\Price">
210+
<column name="subtotal" class="Magento\Sales\Ui\Component\Listing\Column\PurchasedPrice">
211211
<settings>
212212
<filter>textRange</filter>
213213
<label translate="true">Subtotal</label>
214214
<visible>false</visible>
215215
</settings>
216216
</column>
217-
<column name="shipping_and_handling" class="Magento\Sales\Ui\Component\Listing\Column\Price">
217+
<column name="shipping_and_handling" class="Magento\Sales\Ui\Component\Listing\Column\PurchasedPrice">
218218
<settings>
219219
<filter>textRange</filter>
220220
<label translate="true">Shipping &amp; Handling</label>

0 commit comments

Comments
 (0)