Skip to content

Commit 5474b5f

Browse files
committed
Rewrite methods which was removed in first commit
1 parent 6e2d0c8 commit 5474b5f

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

app/code/Magento/Sales/Model/Order/Config.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,23 @@ protected function _getStatuses($visibility)
300300
}
301301
return $this->statuses[(bool) $visibility];
302302
}
303+
304+
/**
305+
* Retrieve label by state and status
306+
*
307+
* @param string $state
308+
* @param string $status
309+
* @return \Magento\Framework\Phrase|string
310+
* @since 100.2.0
311+
*/
312+
public function getStateLabelByStateAndStatus($state, $status)
313+
{
314+
foreach ($this->_getCollection() as $item) {
315+
if ($item->getData('state') == $state && $item->getData('status') == $status) {
316+
$label = $item->getData('label');
317+
return __($label);
318+
}
319+
}
320+
return $state;
321+
}
303322
}

app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,38 @@ public function testGetInvisibleOnFrontStatuses()
116116
$this->assertSame($expectedResult, $result);
117117
}
118118

119+
/**
120+
* @return void
121+
*/
122+
public function testGetStateLabelByStateAndStatus()
123+
{
124+
$statuses = [
125+
new DataObject(
126+
[
127+
'status' => 'fraud',
128+
'state' => 'processing',
129+
'label' => 'Suspected Fraud',
130+
]
131+
),
132+
new DataObject(
133+
[
134+
'status' => 'processing',
135+
'state' => 'processing',
136+
'label' => 'Processing',
137+
]
138+
)
139+
];
140+
$collectionMock = $this->createPartialMock(Collection::class, ['create', 'joinStates']);
141+
$this->orderStatusCollectionFactoryMock->expects($this->once())
142+
->method('create')
143+
->will($this->returnValue($collectionMock));
144+
$collectionMock->expects($this->once())
145+
->method('joinStates')
146+
->will($this->returnValue($statuses));
147+
$result = $this->salesConfig->getStateLabelByStateAndStatus('processing', 'fraud');
148+
$this->assertSame('Suspected Fraud', $result->getText());
149+
}
150+
119151
/**
120152
* Test get statuses
121153
*

0 commit comments

Comments
 (0)