Skip to content

Commit b32548c

Browse files
committed
MAGETWO-37398: [GITHUB] in dashboard Last Orders items quantity showing wrong some times #1272
1 parent 1ea9173 commit b32548c

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ protected function calculateItems(\Magento\Sales\Model\Order $object)
126126
$parent = $item->getQuoteParentItemId();
127127
if ($parent && !$item->getParentItem()) {
128128
$item->setParentItem($object->getItemByQuoteItemId($parent));
129-
} elseif (!$parent) {
129+
}
130+
$childItems = $item->getChildrenItems();
131+
if (empty($childItems)) {
130132
$itemsCount++;
131133
}
132134
}

app/code/Magento/Sales/Test/Unit/Model/Resource/OrderTest.php

+52-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,18 @@ class OrderTest extends \PHPUnit_Framework_TestCase
3838
* @var \Magento\Sales\Model\Order|\PHPUnit_Framework_MockObject_MockObject
3939
*/
4040
protected $orderMock;
41+
/**
42+
* @var \Magento\Sales\Model\Order\Item|\PHPUnit_Framework_MockObject_MockObject
43+
*/
44+
protected $orderItemMock;
4145
/**
4246
* @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject
4347
*/
4448
protected $storeMock;
49+
/**
50+
* @var \Magento\Store\Model\Website|\PHPUnit_Framework_MockObject_MockObject
51+
*/
52+
protected $websiteMock;
4553
/**
4654
* @var \Magento\Store\Model\Group|\PHPUnit_Framework_MockObject_MockObject
4755
*/
@@ -71,8 +79,28 @@ public function setUp()
7179
{
7280
$this->resourceMock = $this->getMock('Magento\Framework\App\Resource', [], [], '', false);
7381
$this->orderMock = $this->getMock('Magento\Sales\Model\Order', [], [], '', false);
82+
$this->orderItemMock = $this->getMock(
83+
'Magento\Sales\Model\Order\Item',
84+
['getQuoteParentItemId', 'setTotalItemCount', 'getChildrenItems'],
85+
[],
86+
'',
87+
false
88+
);
7489
$this->storeMock = $this->getMock('Magento\Store\Model\Store', [], [], '', false);
75-
$this->storeGroupMock = $this->getMock('Magento\Store\Model\Group', [], [], '', false);
90+
$this->storeGroupMock = $this->getMock(
91+
'Magento\Store\Model\Group',
92+
['getName', 'getDefaultStoreId'],
93+
[],
94+
'',
95+
false
96+
);
97+
$this->websiteMock = $this->getMock(
98+
'Magento\Store\Model\Website',
99+
['getName'],
100+
[],
101+
'',
102+
false
103+
);
76104
$this->adapterMock = $this->getMock(
77105
'Magento\Framework\DB\Adapter\Pdo\Mysql',
78106
[
@@ -138,7 +166,24 @@ public function setUp()
138166

139167
public function testSave()
140168
{
141-
169+
$this->orderMock->expects($this->exactly(3))
170+
->method('getId')
171+
->willReturn(null);
172+
$this->orderItemMock->expects($this->once())
173+
->method('getChildrenItems')
174+
->willReturn([]);
175+
$this->orderItemMock->expects($this->once())
176+
->method('getQuoteParentItemId')
177+
->willReturn(null);
178+
$this->orderMock->expects($this->once())
179+
->method('setTotalItemCount')
180+
->with(1);
181+
$this->storeGroupMock->expects($this->once())
182+
->method('getDefaultStoreId')
183+
->willReturn(1);
184+
$this->orderMock->expects($this->once())
185+
->method('getAllItems')
186+
->willReturn([$this->orderItemMock]);
142187
$this->orderMock->expects($this->once())
143188
->method('validateBeforeSave')
144189
->willReturnSelf();
@@ -151,12 +196,15 @@ public function testSave()
151196
$this->orderMock->expects($this->once())
152197
->method('getEntityType')
153198
->willReturn('order');
154-
$this->orderMock->expects($this->once())
199+
$this->orderMock->expects($this->exactly(2))
155200
->method('getStore')
156201
->willReturn($this->storeMock);
157-
$this->storeMock->expects($this->once())
202+
$this->storeMock->expects($this->exactly(2))
158203
->method('getGroup')
159204
->willReturn($this->storeGroupMock);
205+
$this->storeMock->expects($this->once())
206+
->method('getWebsite')
207+
->willReturn($this->websiteMock);
160208
$this->storeGroupMock->expects($this->once())
161209
->method('getDefaultStoreId')
162210
->willReturn(1);

0 commit comments

Comments
 (0)