diff --git a/app/code/Magento/Sales/Model/Order/Config.php b/app/code/Magento/Sales/Model/Order/Config.php index 1c7514142678b..e00eda647dc8d 100644 --- a/app/code/Magento/Sales/Model/Order/Config.php +++ b/app/code/Magento/Sales/Model/Order/Config.php @@ -122,8 +122,14 @@ public function getStateDefaultStatus($state) */ public function getStatusLabel($code) { - $code = $this->maskStatusForArea($this->state->getAreaCode(), $code); + $area = $this->state->getAreaCode(); + $code = $this->maskStatusForArea($area, $code); $status = $this->orderStatusFactory->create()->load($code); + + if ($area == 'adminhtml') { + return $status->getLabel(); + } + return $status->getStoreLabel(); } @@ -211,7 +217,7 @@ public function getStateStatuses($state, $addLabels = true) foreach ($collection as $item) { $status = $item->getData('status'); if ($addLabels) { - $statuses[$status] = $item->getStoreLabel(); + $statuses[$status] = $this->getStatusLabel($status); } else { $statuses[] = $status; } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php index f3a35e485c166..86419c0c905b6 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php @@ -23,18 +23,41 @@ class ConfigTest extends \PHPUnit\Framework\TestCase */ protected $orderStatusCollectionFactoryMock; + /** + * @var \Magento\Sales\Model\Order\StatusFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $statusFactoryMock; + + /** + * @var \Magento\Sales\Model\Order\Status + */ + protected $orderStatusModel; + + /** + * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $storeManagerMock; + protected function setUp() { - $orderStatusFactory = $this->createMock(\Magento\Sales\Model\Order\StatusFactory::class); + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class); + $this->orderStatusModel = $objectManager->getObject(\Magento\Sales\Model\Order\Status::class, [ + 'storeManager' => $this->storeManagerMock, + ]); + $this->statusFactoryMock = $this->getMockBuilder(\Magento\Sales\Model\Order\StatusFactory::class) + ->setMethods(['load', 'create']) + ->getMock(); $this->orderStatusCollectionFactoryMock = $this->createPartialMock( \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory::class, ['create'] ); - $this->salesConfig = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this)) + $this->salesConfig = $objectManager ->getObject( \Magento\Sales\Model\Order\Config::class, [ - 'orderStatusFactory' => $orderStatusFactory, + 'orderStatusFactory' => $this->statusFactoryMock, 'orderStatusCollectionFactory' => $this->orderStatusCollectionFactoryMock ] ); @@ -147,6 +170,22 @@ public function testGetStatuses($state, $joinLabels, $collectionData, $expectedR ->method('joinStates') ->will($this->returnValue($collectionData)); + $this->statusFactoryMock->method('create') + ->willReturnSelf(); + + $this->statusFactoryMock->method('load') + ->willReturn($this->orderStatusModel); + + $storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class); + $storeMock->method('getId') + ->willReturn(1); + + $this->storeManagerMock->method('getStore') + ->with($this->anything()) + ->willReturn($storeMock); + + $this->orderStatusModel->setData('store_labels', [1 => 'Pending label']); + $result = $this->salesConfig->getStateStatuses($state, $joinLabels); $this->assertSame($expectedResult, $result); diff --git a/app/code/Magento/Sales/view/adminhtml/templates/order/view/history.phtml b/app/code/Magento/Sales/view/adminhtml/templates/order/view/history.phtml index 1ec51ffb793c6..6ac6e13a873ed 100644 --- a/app/code/Magento/Sales/view/adminhtml/templates/order/view/history.phtml +++ b/app/code/Magento/Sales/view/adminhtml/templates/order/view/history.phtml @@ -5,7 +5,7 @@ */ // @codingStandardsIgnoreFile - +/** @var \Magento\Sales\Block\Adminhtml\Order\View\History $block */ ?>
canAddComment()):?> diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/Order/StatusTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/StatusTest.php new file mode 100644 index 0000000000000..e4b64e77d6e05 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/StatusTest.php @@ -0,0 +1,49 @@ + [ + 'adminhtml', + 'Example', + ], + 'store view label' => [ + 'frontend', + 'Store view example', + ], + ]; + } + + /** + * In the backend the regular label must be showed. + * + * @param $area + * @param $result + * + * @magentoDataFixture Magento/Sales/_files/order_status.php + * @dataProvider theCorrectLabelIsUsedDependingOnTheAreaProvider + */ + public function testTheCorrectLabelIsUsedDependingOnTheArea($area, $result) + { + $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $objectManager->get(\Magento\Framework\App\State::class)->setAreaCode($area); + + /** @var \Magento\Sales\Model\Order $order */ + $order = $objectManager->create(\Magento\Sales\Model\Order::class); + $order->loadByIncrementId('100000001'); + + $this->assertEquals($result, $order->getStatusLabel()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/order_status.php b/dev/tests/integration/testsuite/Magento/Sales/_files/order_status.php new file mode 100644 index 0000000000000..e65dd6b682396 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Sales/_files/order_status.php @@ -0,0 +1,25 @@ +create( + \Magento\Sales\Model\Order\Status::class +); + +$data = [ + 'status' => 'example', + 'label' => 'Example', + 'store_labels' => [ + 1 => 'Store view example', + ] +]; + +$orderStatus->setData($data)->setStatus('example'); +$orderStatus->save(); + +$order->setStatus('example'); +$order->save();