Skip to content

Commit

Permalink
MAGETWO-37398: [GITHUB] in dashboard Last Orders items quantity showi…
Browse files Browse the repository at this point in the history
…ng wrong some times #1272
  • Loading branch information
akaplya committed Jul 14, 2015
1 parent 1ea9173 commit b32548c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/code/Magento/Sales/Model/Resource/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ protected function calculateItems(\Magento\Sales\Model\Order $object)
$parent = $item->getQuoteParentItemId();
if ($parent && !$item->getParentItem()) {
$item->setParentItem($object->getItemByQuoteItemId($parent));
} elseif (!$parent) {
}
$childItems = $item->getChildrenItems();
if (empty($childItems)) {
$itemsCount++;
}
}
Expand Down
56 changes: 52 additions & 4 deletions app/code/Magento/Sales/Test/Unit/Model/Resource/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@ class OrderTest extends \PHPUnit_Framework_TestCase
* @var \Magento\Sales\Model\Order|\PHPUnit_Framework_MockObject_MockObject
*/
protected $orderMock;
/**
* @var \Magento\Sales\Model\Order\Item|\PHPUnit_Framework_MockObject_MockObject
*/
protected $orderItemMock;
/**
* @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject
*/
protected $storeMock;
/**
* @var \Magento\Store\Model\Website|\PHPUnit_Framework_MockObject_MockObject
*/
protected $websiteMock;
/**
* @var \Magento\Store\Model\Group|\PHPUnit_Framework_MockObject_MockObject
*/
Expand Down Expand Up @@ -71,8 +79,28 @@ public function setUp()
{
$this->resourceMock = $this->getMock('Magento\Framework\App\Resource', [], [], '', false);
$this->orderMock = $this->getMock('Magento\Sales\Model\Order', [], [], '', false);
$this->orderItemMock = $this->getMock(
'Magento\Sales\Model\Order\Item',
['getQuoteParentItemId', 'setTotalItemCount', 'getChildrenItems'],
[],
'',
false
);
$this->storeMock = $this->getMock('Magento\Store\Model\Store', [], [], '', false);
$this->storeGroupMock = $this->getMock('Magento\Store\Model\Group', [], [], '', false);
$this->storeGroupMock = $this->getMock(
'Magento\Store\Model\Group',
['getName', 'getDefaultStoreId'],
[],
'',
false
);
$this->websiteMock = $this->getMock(
'Magento\Store\Model\Website',
['getName'],
[],
'',
false
);
$this->adapterMock = $this->getMock(
'Magento\Framework\DB\Adapter\Pdo\Mysql',
[
Expand Down Expand Up @@ -138,7 +166,24 @@ public function setUp()

public function testSave()
{

$this->orderMock->expects($this->exactly(3))
->method('getId')
->willReturn(null);
$this->orderItemMock->expects($this->once())
->method('getChildrenItems')
->willReturn([]);
$this->orderItemMock->expects($this->once())
->method('getQuoteParentItemId')
->willReturn(null);
$this->orderMock->expects($this->once())
->method('setTotalItemCount')
->with(1);
$this->storeGroupMock->expects($this->once())
->method('getDefaultStoreId')
->willReturn(1);
$this->orderMock->expects($this->once())
->method('getAllItems')
->willReturn([$this->orderItemMock]);
$this->orderMock->expects($this->once())
->method('validateBeforeSave')
->willReturnSelf();
Expand All @@ -151,12 +196,15 @@ public function testSave()
$this->orderMock->expects($this->once())
->method('getEntityType')
->willReturn('order');
$this->orderMock->expects($this->once())
$this->orderMock->expects($this->exactly(2))
->method('getStore')
->willReturn($this->storeMock);
$this->storeMock->expects($this->once())
$this->storeMock->expects($this->exactly(2))
->method('getGroup')
->willReturn($this->storeGroupMock);
$this->storeMock->expects($this->once())
->method('getWebsite')
->willReturn($this->websiteMock);
$this->storeGroupMock->expects($this->once())
->method('getDefaultStoreId')
->willReturn(1);
Expand Down

0 comments on commit b32548c

Please sign in to comment.