Skip to content

Commit 88a3ad0

Browse files
⏫ Forwardport of #11397 to 2.3-develop branch
Applied pull request patch https://github.com/magento/magento2/pull/11397.patch (created by @michielgerritsen) based on commit(s): 1. 9ee464c 2. 8e843ad 3. 69ef9da 4. 4660956 5. 567b331 6. 1ad99bc 7. 0784f58 Fixed GitHub Issues in 2.3-develop branch: - #9566: Status label is wrong in admin (reported by @darkogoles1)
1 parent 8e77e2f commit 88a3ad0

File tree

5 files changed

+125
-6
lines changed

5 files changed

+125
-6
lines changed

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,14 @@ public function getStateDefaultStatus($state)
122122
*/
123123
public function getStatusLabel($code)
124124
{
125-
$code = $this->maskStatusForArea($this->state->getAreaCode(), $code);
125+
$area = $this->state->getAreaCode();
126+
$code = $this->maskStatusForArea($area, $code);
126127
$status = $this->orderStatusFactory->create()->load($code);
128+
129+
if ($area == 'adminhtml') {
130+
return $status->getLabel();
131+
}
132+
127133
return $status->getStoreLabel();
128134
}
129135

@@ -211,7 +217,7 @@ public function getStateStatuses($state, $addLabels = true)
211217
foreach ($collection as $item) {
212218
$status = $item->getData('status');
213219
if ($addLabels) {
214-
$statuses[$status] = $item->getStoreLabel();
220+
$statuses[$status] = $this->getStatusLabel($status);
215221
} else {
216222
$statuses[] = $status;
217223
}

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

+42-3
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,41 @@ class ConfigTest extends \PHPUnit\Framework\TestCase
2323
*/
2424
protected $orderStatusCollectionFactoryMock;
2525

26+
/**
27+
* @var \Magento\Sales\Model\Order\StatusFactory|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
protected $statusFactoryMock;
30+
31+
/**
32+
* @var \Magento\Sales\Model\Order\Status
33+
*/
34+
protected $orderStatusModel;
35+
36+
/**
37+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
38+
*/
39+
protected $storeManagerMock;
40+
2641
protected function setUp()
2742
{
28-
$orderStatusFactory = $this->createMock(\Magento\Sales\Model\Order\StatusFactory::class);
43+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
44+
45+
$this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
46+
$this->orderStatusModel = $objectManager->getObject(\Magento\Sales\Model\Order\Status::class, [
47+
'storeManager' => $this->storeManagerMock,
48+
]);
49+
$this->statusFactoryMock = $this->getMockBuilder(\Magento\Sales\Model\Order\StatusFactory::class)
50+
->setMethods(['load', 'create'])
51+
->getMock();
2952
$this->orderStatusCollectionFactoryMock = $this->createPartialMock(
3053
\Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory::class,
3154
['create']
3255
);
33-
$this->salesConfig = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
56+
$this->salesConfig = $objectManager
3457
->getObject(
3558
\Magento\Sales\Model\Order\Config::class,
3659
[
37-
'orderStatusFactory' => $orderStatusFactory,
60+
'orderStatusFactory' => $this->statusFactoryMock,
3861
'orderStatusCollectionFactory' => $this->orderStatusCollectionFactoryMock
3962
]
4063
);
@@ -147,6 +170,22 @@ public function testGetStatuses($state, $joinLabels, $collectionData, $expectedR
147170
->method('joinStates')
148171
->will($this->returnValue($collectionData));
149172

173+
$this->statusFactoryMock->method('create')
174+
->willReturnSelf();
175+
176+
$this->statusFactoryMock->method('load')
177+
->willReturn($this->orderStatusModel);
178+
179+
$storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);
180+
$storeMock->method('getId')
181+
->willReturn(1);
182+
183+
$this->storeManagerMock->method('getStore')
184+
->with($this->anything())
185+
->willReturn($storeMock);
186+
187+
$this->orderStatusModel->setData('store_labels', [1 => 'Pending label']);
188+
150189
$result = $this->salesConfig->getStateStatuses($state, $joinLabels);
151190
$this->assertSame($expectedResult, $result);
152191

app/code/Magento/Sales/view/adminhtml/templates/order/view/history.phtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
// @codingStandardsIgnoreFile
8-
8+
/** @var \Magento\Sales\Block\Adminhtml\Order\View\History $block */
99
?>
1010
<div id="order_history_block" class="edit-order-comments">
1111
<?php if ($block->canAddComment()):?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Sales\Model\Order;
8+
9+
/**
10+
* Class ShipmentTest
11+
* @package Magento\Sales\Model\Order
12+
*/
13+
class StatusTest extends \PHPUnit\Framework\TestCase
14+
{
15+
public function theCorrectLabelIsUsedDependingOnTheAreaProvider()
16+
{
17+
return [
18+
'backend label' => [
19+
'adminhtml',
20+
'Example',
21+
],
22+
'store view label' => [
23+
'frontend',
24+
'Store view example',
25+
],
26+
];
27+
}
28+
29+
/**
30+
* In the backend the regular label must be showed.
31+
*
32+
* @param $area
33+
* @param $result
34+
*
35+
* @magentoDataFixture Magento/Sales/_files/order_status.php
36+
* @dataProvider theCorrectLabelIsUsedDependingOnTheAreaProvider
37+
*/
38+
public function testTheCorrectLabelIsUsedDependingOnTheArea($area, $result)
39+
{
40+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
41+
$objectManager->get(\Magento\Framework\App\State::class)->setAreaCode($area);
42+
43+
/** @var \Magento\Sales\Model\Order $order */
44+
$order = $objectManager->create(\Magento\Sales\Model\Order::class);
45+
$order->loadByIncrementId('100000001');
46+
47+
$this->assertEquals($result, $order->getStatusLabel());
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
require __DIR__ . '/order.php';
8+
9+
$orderStatus = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
10+
\Magento\Sales\Model\Order\Status::class
11+
);
12+
13+
$data = [
14+
'status' => 'example',
15+
'label' => 'Example',
16+
'store_labels' => [
17+
1 => 'Store view example',
18+
]
19+
];
20+
21+
$orderStatus->setData($data)->setStatus('example');
22+
$orderStatus->save();
23+
24+
$order->setStatus('example');
25+
$order->save();

0 commit comments

Comments
 (0)