Skip to content

Commit 0861545

Browse files
committed
Merge pull request #630 from magento-troll/MerchantBetaBugFixes
[Merchant Beta][MX] Bugfixes
2 parents a218146 + f0e7364 commit 0861545

File tree

2 files changed

+36
-43
lines changed

2 files changed

+36
-43
lines changed

app/code/Magento/CatalogInventory/Helper/Stock.php

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,16 @@
55
*/
66
namespace Magento\CatalogInventory\Helper;
77

8-
use Magento\CatalogInventory\Api\StockRegistryInterface;
8+
use Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface;
99
use Magento\Store\Model\StoreManagerInterface;
1010
use Magento\Framework\App\Config\ScopeConfigInterface;
11-
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\CatalogInventory\Model\Resource\Stock\StatusFactory;
1212

1313
/**
1414
* Class Stock
1515
*/
1616
class Stock
1717
{
18-
/**
19-
* @var StockRegistryInterface
20-
*/
21-
protected $stockRegistry;
22-
2318
/**
2419
* Store model manager
2520
*
@@ -40,26 +35,31 @@ class Stock
4035
protected $stockStatusResource;
4136

4237
/**
43-
* @var \Magento\Framework\ObjectManagerInterface
38+
* @var StatusFactory
39+
*/
40+
protected $stockStatusFactory;
41+
42+
/**
43+
* @var StockRegistryProviderInterface
4444
*/
45-
protected $objectManger;
45+
private $stockRegistryProvider;
4646

4747
/**
48-
* @param StockRegistryInterface $stockRegistry
4948
* @param StoreManagerInterface $storeManager
5049
* @param ScopeConfigInterface $scopeConfig
51-
* @param ObjectManagerInterface $objectManager
50+
* @param StatusFactory $stockStatusFactory
51+
* @param StockRegistryProviderInterface $stockRegistryProvider
5252
*/
5353
public function __construct(
54-
StockRegistryInterface $stockRegistry,
5554
StoreManagerInterface $storeManager,
5655
ScopeConfigInterface $scopeConfig,
57-
ObjectManagerInterface $objectManager
56+
StatusFactory $stockStatusFactory,
57+
StockRegistryProviderInterface $stockRegistryProvider
5858
) {
59-
$this->stockRegistry = $stockRegistry;
6059
$this->storeManager = $storeManager;
6160
$this->scopeConfig = $scopeConfig;
62-
$this->objectManger = $objectManager;
61+
$this->stockStatusFactory = $stockStatusFactory;
62+
$this->stockRegistryProvider = $stockRegistryProvider;
6363
}
6464

6565
/**
@@ -73,7 +73,7 @@ public function assignStatusToProduct(\Magento\Catalog\Model\Product $product, $
7373
{
7474
if ($stockStatus === null) {
7575
$websiteId = $product->getStore()->getWebsiteId();
76-
$stockStatus = $this->stockRegistry->getStockStatus($product->getId(), $websiteId);
76+
$stockStatus = $this->stockRegistryProvider->getStockStatus($product->getId(), $websiteId);
7777
$status = $stockStatus->getStockStatus();
7878
}
7979
$product->setIsSalable($status);
@@ -90,10 +90,9 @@ public function addStockStatusToProducts(
9090
\Magento\Catalog\Model\Resource\Collection\AbstractCollection $productCollection
9191
) {
9292
$websiteId = $this->storeManager->getStore($productCollection->getStoreId())->getWebsiteId();
93-
$productIds = [];
9493
foreach ($productCollection as $product) {
9594
$productId = $product->getId();
96-
$stockStatus = $this->stockRegistry->getStockStatus($productId, $websiteId);
95+
$stockStatus = $this->stockRegistryProvider->getStockStatus($productId, $websiteId);
9796
$status = $stockStatus->getStockStatus();
9897
$product->setIsSalable($status);
9998
}
@@ -162,9 +161,7 @@ public function addIsInStockFilterToCollection($collection)
162161
protected function getStockStatusResource()
163162
{
164163
if (empty($this->stockStatusResource)) {
165-
$this->stockStatusResource = $this->objectManger->get(
166-
'Magento\CatalogInventory\Model\Resource\Stock\Status'
167-
);
164+
$this->stockStatusResource = $this->stockStatusFactory->create();
168165
}
169166
return $this->stockStatusResource;
170167
}

app/code/Magento/CatalogInventory/Test/Unit/Helper/StockTest.php

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,29 @@ class StockTest extends \PHPUnit_Framework_TestCase
1818
protected $stock;
1919

2020
/**
21-
* @var \PHPUnit_Framework_MockObject_MockObject
21+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface
2222
*/
23-
protected $stockRegistryMock;
23+
protected $stockRegistryProviderMock;
2424

2525
/**
26-
* @var \PHPUnit_Framework_MockObject_MockObject
26+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\StoreManagerInterface
2727
*/
2828
protected $storeManagerMock;
2929

3030
/**
31-
* @var \PHPUnit_Framework_MockObject_MockObject
31+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Config\ScopeConfigInterface
3232
*/
3333
protected $scopeConfigMock;
3434

3535
/**
36-
* @var \PHPUnit_Framework_MockObject_MockObject
36+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\CatalogInventory\Model\Resource\Stock\StatusFactory
3737
*/
38-
protected $productFactoryMock;
39-
40-
/**
41-
* @var \PHPUnit_Framework_MockObject_MockObject
42-
*/
43-
protected $objectManagerMock;
38+
protected $statusFactoryMock;
4439

4540
protected function setUp()
4641
{
47-
$this->stockRegistryMock = $this->getMockBuilder(
48-
'Magento\CatalogInventory\Api\StockRegistryInterface'
42+
$this->stockRegistryProviderMock = $this->getMockBuilder(
43+
'Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface'
4944
)
5045
->disableOriginalConstructor()
5146
->getMock();
@@ -55,14 +50,15 @@ protected function setUp()
5550
$this->scopeConfigMock = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface')
5651
->disableOriginalConstructor()
5752
->getMock();
58-
$this->objectManagerMock = $this->getMockBuilder('Magento\Framework\App\ObjectManager')
53+
$this->statusFactoryMock = $this->getMockBuilder('Magento\CatalogInventory\Model\Resource\Stock\StatusFactory')
5954
->disableOriginalConstructor()
55+
->setMethods(['create'])
6056
->getMock();
6157
$this->stock = new Stock(
62-
$this->stockRegistryMock,
6358
$this->storeManagerMock,
6459
$this->scopeConfigMock,
65-
$this->objectManagerMock
60+
$this->statusFactoryMock,
61+
$this->stockRegistryProviderMock
6662
);
6763
}
6864

@@ -77,7 +73,7 @@ public function testAssignStatusToProduct()
7773
$stockStatusMock->expects($this->any())
7874
->method('getStockStatus')
7975
->willReturn($status);
80-
$this->stockRegistryMock->expects($this->any())
76+
$this->stockRegistryProviderMock->expects($this->any())
8177
->method('getStockStatus')
8278
->willReturn($stockStatusMock);
8379
$storeMock = $this->getMockBuilder('Magento\Store\Model\Store')
@@ -142,7 +138,7 @@ public function testAddStockStatusToProducts()
142138
$this->storeManagerMock->expects($this->once())
143139
->method('getStore')
144140
->willReturn($storeMock);
145-
$this->stockRegistryMock->expects($this->once())
141+
$this->stockRegistryProviderMock->expects($this->once())
146142
->method('getStockStatus')
147143
->withAnyParameters()
148144
->willReturn($stockStatusMock);
@@ -192,8 +188,8 @@ public function testAddStockStatusToSelect()
192188
$stockStatusMock->expects($this->once())
193189
->method('addStockStatusToSelect')
194190
->with($selectMock, $websiteMock);
195-
$this->objectManagerMock->expects($this->once())
196-
->method('get')
191+
$this->statusFactoryMock->expects($this->once())
192+
->method('create')
197193
->willReturn($stockStatusMock);
198194

199195
$this->assertNull($this->stock->addStockStatusToSelect($selectMock, $websiteMock));
@@ -211,8 +207,8 @@ public function testAddIsInStockFilterToCollection()
211207
$stockStatusMock->expects($this->once())
212208
->method('addIsInStockFilterToCollection')
213209
->with($collectionMock);
214-
$this->objectManagerMock->expects($this->once())
215-
->method('get')
210+
$this->statusFactoryMock->expects($this->once())
211+
->method('create')
216212
->willReturn($stockStatusMock);
217213

218214
$this->assertNull($this->stock->addIsInStockFilterToCollection($collectionMock));

0 commit comments

Comments
 (0)