5
5
*/
6
6
namespace Magento \CatalogInventory \Model \ResourceModel \Stock ;
7
7
8
- use Magento \CatalogInventory \Model \Stock ;
9
8
use Magento \CatalogInventory \Api \StockConfigurationInterface ;
9
+ use Magento \CatalogInventory \Model \Stock ;
10
10
use Magento \Framework \App \ObjectManager ;
11
11
12
12
/**
@@ -46,19 +46,23 @@ class Status extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
46
46
* @param \Magento\Store\Model\WebsiteFactory $websiteFactory
47
47
* @param \Magento\Eav\Model\Config $eavConfig
48
48
* @param string $connectionName
49
+ * @param \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration
49
50
*/
50
51
public function __construct (
51
52
\Magento \Framework \Model \ResourceModel \Db \Context $ context ,
52
53
\Magento \Store \Model \StoreManagerInterface $ storeManager ,
53
54
\Magento \Store \Model \WebsiteFactory $ websiteFactory ,
54
55
\Magento \Eav \Model \Config $ eavConfig ,
55
- $ connectionName = null
56
+ $ connectionName = null ,
57
+ $ stockConfiguration = null
56
58
) {
57
59
parent ::__construct ($ context , $ connectionName );
58
60
59
61
$ this ->_storeManager = $ storeManager ;
60
62
$ this ->_websiteFactory = $ websiteFactory ;
61
63
$ this ->eavConfig = $ eavConfig ;
64
+ $ this ->stockConfiguration = $ stockConfiguration ?: ObjectManager::getInstance ()
65
+ ->get (StockConfigurationInterface::class);
62
66
}
63
67
64
68
/**
@@ -204,7 +208,7 @@ public function getProductCollection($lastEntityId = 0, $limit = 1000)
204
208
*/
205
209
public function addStockStatusToSelect (\Magento \Framework \DB \Select $ select , \Magento \Store \Model \Website $ website )
206
210
{
207
- $ websiteId = $ this ->getStockConfiguration ()-> getDefaultScopeId ( );
211
+ $ websiteId = $ this ->getWebsiteId ( $ website -> getId () );
208
212
$ select ->joinLeft (
209
213
['stock_status ' => $ this ->getMainTable ()],
210
214
'e.entity_id = stock_status.product_id AND stock_status.website_id= ' . $ websiteId ,
@@ -221,7 +225,7 @@ public function addStockStatusToSelect(\Magento\Framework\DB\Select $select, \Ma
221
225
*/
222
226
public function addStockDataToCollection ($ collection , $ isFilterInStock )
223
227
{
224
- $ websiteId = $ this ->getStockConfiguration ()-> getDefaultScopeId ();
228
+ $ websiteId = $ this ->getWebsiteId ();
225
229
$ joinCondition = $ this ->getConnection ()->quoteInto (
226
230
'e.entity_id = stock_status_index.product_id ' . ' AND stock_status_index.website_id = ? ' ,
227
231
$ websiteId
@@ -255,7 +259,7 @@ public function addStockDataToCollection($collection, $isFilterInStock)
255
259
*/
256
260
public function addIsInStockFilterToCollection ($ collection )
257
261
{
258
- $ websiteId = $ this ->getStockConfiguration ()-> getDefaultScopeId ();
262
+ $ websiteId = $ this ->getWebsiteId ();
259
263
$ joinCondition = $ this ->getConnection ()->quoteInto (
260
264
'e.entity_id = stock_status_index.product_id ' . ' AND stock_status_index.website_id = ? ' ,
261
265
$ websiteId
@@ -277,6 +281,19 @@ public function addIsInStockFilterToCollection($collection)
277
281
return $ this ;
278
282
}
279
283
284
+ /**
285
+ * @param \Magento\Store\Model\Website $websiteId
286
+ * @return int
287
+ */
288
+ private function getWebsiteId ($ websiteId = null )
289
+ {
290
+ if (null === $ websiteId ) {
291
+ $ websiteId = $ this ->stockConfiguration ->getDefaultScopeId ();
292
+ }
293
+
294
+ return $ websiteId ;
295
+ }
296
+
280
297
/**
281
298
* Retrieve Product(s) status for store
282
299
* Return array where key is a product_id, value - status
@@ -335,18 +352,4 @@ public function getProductStatus($productIds, $storeId = null)
335
352
}
336
353
return $ statuses ;
337
354
}
338
-
339
- /**
340
- * @return StockConfigurationInterface
341
- *
342
- * @deprecated 100.1.0
343
- */
344
- private function getStockConfiguration ()
345
- {
346
- if ($ this ->stockConfiguration === null ) {
347
- $ this ->stockConfiguration = \Magento \Framework \App \ObjectManager::getInstance ()
348
- ->get (\Magento \CatalogInventory \Api \StockConfigurationInterface::class);
349
- }
350
- return $ this ->stockConfiguration ;
351
- }
352
355
}
0 commit comments