Skip to content

Commit 2c5dd78

Browse files
author
Yaroslav Onischenko
committed
MAGETWO-36908: Stock Items API service to return low stock information does not return the correct results
1 parent 3c66c19 commit 2c5dd78

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

app/code/Magento/CatalogInventory/Model/StockRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function getLowStockItems($websiteId, $qty, $currentPage = 1, $pageSize =
172172
$criteria = $this->criteriaFactory->create();
173173
$criteria->setLimit($currentPage, $pageSize);
174174
$criteria->setWebsiteFilter($websiteId);
175-
$criteria->setQtyFilter('>=', $qty);
175+
$criteria->setQtyFilter('<=', $qty);
176176
$criteria->addField('qty');
177177
return $this->stockItemRepository->getList($criteria);
178178
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogInventory\Test\Unit\Model;
7+
8+
/**
9+
* Class StockRegistryTest
10+
*/
11+
class StockRegistryTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var \Magento\CatalogInventory\Model\StockRegistry
15+
*/
16+
protected $model;
17+
18+
/**
19+
* @var \PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
protected $criteria;
22+
23+
public function setUp()
24+
{
25+
$this->criteria = $this->getMockBuilder('Magento\CatalogInventory\Api\StockItemCriteriaInterface')
26+
->disableOriginalConstructor()
27+
->getMock();
28+
29+
$criteriaFactory = $this->getMockBuilder('Magento\CatalogInventory\Api\StockItemCriteriaInterfaceFactory')
30+
->disableOriginalConstructor()
31+
->getMock();
32+
$criteriaFactory->expects($this->once())->method('create')->willReturn($this->criteria);
33+
34+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
35+
$this->model = $objectManager->getObject(
36+
'Magento\CatalogInventory\Model\StockRegistry',
37+
[
38+
'criteriaFactory' => $criteriaFactory
39+
]
40+
);
41+
}
42+
43+
public function testGetLowStockItems()
44+
{
45+
$this->criteria->expects($this->once())->method('setLimit')->with(1, 0);
46+
$this->criteria->expects($this->once())->method('setWebsiteFilter')->with(1);
47+
$this->criteria->expects($this->once())->method('setQtyFilter')->with('<=');
48+
$this->criteria->expects($this->once())->method('addField')->with('qty');
49+
$this->model->getLowStockItems(1, 100);
50+
}
51+
}

0 commit comments

Comments
 (0)