Skip to content

Commit f8625fb

Browse files
author
Serhii Balko
committed
Merge remote-tracking branch 'origin/MC-40030' into 2.4-develop-pr49
2 parents 7e987fc + bb1f08f commit f8625fb

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

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

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
use PHPUnit\Framework\MockObject\MockObject;
1818
use PHPUnit\Framework\TestCase;
1919

20+
/**
21+
* Contains tests for Price class
22+
*/
2023
class PriceTest extends TestCase
2124
{
2225
/**
@@ -34,6 +37,9 @@ class PriceTest extends TestCase
3437
*/
3538
private $storeManagerMock;
3639

40+
/**
41+
* @inheritDoc
42+
*/
3743
protected function setUp(): void
3844
{
3945
$objectManager = new ObjectManager($this);
@@ -57,12 +63,20 @@ protected function setUp(): void
5763
}
5864

5965
/**
60-
* @param $hasCurrency
61-
* @param $dataSource
62-
* @param $currencyCode
66+
* Test for prepareDataSource method
67+
*
68+
* @param bool $hasCurrency
69+
* @param array $dataSource
70+
* @param string $currencyCode
71+
* @param int|null $expectedStoreId
6372
* @dataProvider testPrepareDataSourceDataProvider
6473
*/
65-
public function testPrepareDataSource($hasCurrency, $dataSource, $currencyCode)
74+
public function testPrepareDataSource(
75+
bool $hasCurrency,
76+
array $dataSource,
77+
string $currencyCode,
78+
?int $expectedStoreId = null
79+
): void
6680
{
6781
$itemName = 'itemName';
6882
$oldItemValue = 'oldItemValue';
@@ -79,6 +93,7 @@ public function testPrepareDataSource($hasCurrency, $dataSource, $currencyCode)
7993
->willReturn($currencyCode);
8094
$this->storeManagerMock->expects($hasCurrency ? $this->never() : $this->once())
8195
->method('getStore')
96+
->with($expectedStoreId)
8297
->willReturn($store);
8398
$store->expects($hasCurrency ? $this->never() : $this->once())
8499
->method('getBaseCurrency')
@@ -98,7 +113,12 @@ public function testPrepareDataSource($hasCurrency, $dataSource, $currencyCode)
98113
$this->assertEquals($newItemValue, $dataSource['data']['items'][0][$itemName]);
99114
}
100115

101-
public function testPrepareDataSourceDataProvider()
116+
/**
117+
* Provider for testPrepareDataSource
118+
*
119+
* @return array
120+
*/
121+
public function testPrepareDataSourceDataProvider(): array
102122
{
103123
$dataSource1 = [
104124
'data' => [
@@ -119,9 +139,31 @@ public function testPrepareDataSourceDataProvider()
119139
]
120140
]
121141
];
142+
$dataSource3 = [
143+
'data' => [
144+
'items' => [
145+
[
146+
'itemName' => 'oldItemValue',
147+
'store_id' => '2'
148+
]
149+
]
150+
]
151+
];
152+
$dataSource4 = [
153+
'data' => [
154+
'items' => [
155+
[
156+
'itemName' => 'oldItemValue',
157+
'store_id' => 'abc'
158+
]
159+
]
160+
]
161+
];
122162
return [
123163
[true, $dataSource1, 'US'],
124164
[false, $dataSource2, 'SAR'],
165+
[false, $dataSource3, 'SAR', 2],
166+
[false, $dataSource4, 'SAR'],
125167
];
126168
}
127169
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\Framework\View\Element\UiComponent\ContextInterface;
1212
use Magento\Framework\View\Element\UiComponentFactory;
13+
use Magento\Store\Model\Store;
1314
use Magento\Store\Model\StoreManagerInterface;
1415
use Magento\Ui\Component\Listing\Columns\Column;
1516
use Magento\Framework\Pricing\PriceCurrencyInterface;
@@ -77,8 +78,10 @@ public function prepareDataSource(array $dataSource)
7778
foreach ($dataSource['data']['items'] as & $item) {
7879
$currencyCode = isset($item['base_currency_code']) ? $item['base_currency_code'] : null;
7980
if (!$currencyCode) {
81+
$storeId = isset($item['store_id']) && (int)$item['store_id'] !== 0 ? $item['store_id'] :
82+
$this->context->getFilterParam('store_id', Store::DEFAULT_STORE_ID);
8083
$store = $this->storeManager->getStore(
81-
$this->context->getFilterParam('store_id', \Magento\Store\Model\Store::DEFAULT_STORE_ID)
84+
$storeId
8285
);
8386
$currencyCode = $store->getBaseCurrency()->getCurrencyCode();
8487
}

0 commit comments

Comments
 (0)