Skip to content

Commit ce0032f

Browse files
author
Vladyslav Shcherbyna
committed
MAGETWO-44522: Incorrect currency symbol in Checkout and Orders Grid
1 parent e3593ae commit ce0032f

File tree

5 files changed

+145
-3
lines changed

5 files changed

+145
-3
lines changed

app/code/Magento/Sales/Block/Order/Totals.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ protected function _initTotals()
164164
$this->_totals['base_grandtotal'] = new \Magento\Framework\DataObject(
165165
[
166166
'code' => 'base_grandtotal',
167-
'value' => $this->getOrder()->formatBasePrice($source->getBaseGrandTotal()),
167+
'value' => $this->getOrder()->formatPrice($source->getGrandTotal()),
168168
'label' => __('Grand Total to be Charged'),
169169
'is_formated' => true,
170170
]
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Sales\Test\Unit\Ui\Component\Listing\Column;
7+
8+
use Magento\Framework\Pricing\PriceCurrencyInterface;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\Sales\Ui\Component\Listing\Column\Price;
11+
12+
/**
13+
* Class PurchasedPriceTest
14+
*/
15+
class PurchasedPriceTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var Price
19+
*/
20+
protected $model;
21+
22+
/**
23+
* @var PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
protected $priceFormatterMock;
26+
27+
public function setUp()
28+
{
29+
$objectManager = new ObjectManager($this);
30+
$contextMock = $this->getMockBuilder('Magento\Framework\View\Element\UiComponent\ContextInterface')
31+
->getMockForAbstractClass();
32+
$processor = $this->getMockBuilder('Magento\Framework\View\Element\UiComponent\Processor')
33+
->disableOriginalConstructor()
34+
->getMock();
35+
$contextMock->expects($this->any())->method('getProcessor')->willReturn($processor);
36+
$this->priceFormatterMock = $this->getMockForAbstractClass('Magento\Framework\Pricing\PriceCurrencyInterface');
37+
$this->model = $objectManager->getObject(
38+
'Magento\Sales\Ui\Component\Listing\Column\PurchasedPrice',
39+
['priceFormatter' => $this->priceFormatterMock, 'context' => $contextMock]
40+
);
41+
}
42+
43+
public function testPrepareDataSource()
44+
{
45+
$itemName = 'itemName';
46+
$oldItemValue = 'oldItemValue';
47+
$newItemValue = 'newItemValue';
48+
$dataSource = [
49+
'data' => [
50+
'items' => [
51+
[
52+
$itemName => $oldItemValue,
53+
'order_currency_code' => 'US'
54+
]
55+
]
56+
]
57+
];
58+
59+
$this->priceFormatterMock->expects($this->once())
60+
->method('format')
61+
->with($oldItemValue, false, null, null, 'US')
62+
->willReturn($newItemValue);
63+
64+
$this->model->setData('name', $itemName);
65+
$dataSource = $this->model->prepareDataSource($dataSource);
66+
$this->assertEquals($newItemValue, $dataSource['data']['items'][0][$itemName]);
67+
}
68+
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ public function prepareDataSource(array $dataSource)
5050
{
5151
if (isset($dataSource['data']['items'])) {
5252
foreach ($dataSource['data']['items'] as & $item) {
53-
$item[$this->getData('name')] = $this->priceFormatter->format($item[$this->getData('name')], false);
53+
$currencyCode = isset($item['base_currency_code']) ? $item['base_currency_code'] : null;
54+
$item[$this->getData('name')] = $this->priceFormatter->format(
55+
$item[$this->getData('name')],
56+
false,
57+
null,
58+
null,
59+
$currencyCode
60+
);
5461
}
5562
}
5663

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Sales\Ui\Component\Listing\Column;
7+
8+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
9+
use Magento\Framework\View\Element\UiComponentFactory;
10+
use Magento\Ui\Component\Listing\Columns\Column;
11+
use Magento\Framework\Pricing\PriceCurrencyInterface;
12+
13+
/**
14+
* Class Price
15+
*/
16+
class PurchasedPrice extends Column
17+
{
18+
/**
19+
* @var PriceCurrencyInterface
20+
*/
21+
protected $priceFormatter;
22+
23+
/**
24+
* Constructor
25+
*
26+
* @param ContextInterface $context
27+
* @param UiComponentFactory $uiComponentFactory
28+
* @param PriceCurrencyInterface $priceFormatter
29+
* @param array $components
30+
* @param array $data
31+
*/
32+
public function __construct(
33+
ContextInterface $context,
34+
UiComponentFactory $uiComponentFactory,
35+
PriceCurrencyInterface $priceFormatter,
36+
array $components = [],
37+
array $data = []
38+
) {
39+
$this->priceFormatter = $priceFormatter;
40+
parent::__construct($context, $uiComponentFactory, $components, $data);
41+
}
42+
43+
/**
44+
* Prepare Data Source
45+
*
46+
* @param array $dataSource
47+
* @return array
48+
*/
49+
public function prepareDataSource(array $dataSource)
50+
{
51+
if (isset($dataSource['data']['items'])) {
52+
foreach ($dataSource['data']['items'] as & $item) {
53+
$currencyCode = isset($item['order_currency_code']) ? $item['order_currency_code'] : null;
54+
$item[$this->getData('name')] =
55+
$this->priceFormatter->format(
56+
$item[$this->getData('name')],
57+
false,
58+
null,
59+
null,
60+
$currencyCode
61+
);
62+
}
63+
}
64+
65+
return $dataSource;
66+
}
67+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@
288288
</item>
289289
</argument>
290290
</column>
291-
<column name="grand_total" class="Magento\Sales\Ui\Component\Listing\Column\Price">
291+
<column name="grand_total" class="Magento\Sales\Ui\Component\Listing\Column\PurchasedPrice">
292292
<argument name="data" xsi:type="array">
293293
<item name="config" xsi:type="array">
294294
<item name="filter" xsi:type="string">textRange</item>

0 commit comments

Comments
 (0)