55 */
66namespace Magento \CatalogInventory \Model \ResourceModel \Stock ;
77
8- use Magento \CatalogInventory \Model \Stock ;
98use Magento \CatalogInventory \Api \StockConfigurationInterface ;
9+ use Magento \CatalogInventory \Model \Stock ;
1010use Magento \Framework \App \ObjectManager ;
1111
1212/**
@@ -46,19 +46,23 @@ class Status extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
4646 * @param \Magento\Store\Model\WebsiteFactory $websiteFactory
4747 * @param \Magento\Eav\Model\Config $eavConfig
4848 * @param string $connectionName
49+ * @param \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration
4950 */
5051 public function __construct (
5152 \Magento \Framework \Model \ResourceModel \Db \Context $ context ,
5253 \Magento \Store \Model \StoreManagerInterface $ storeManager ,
5354 \Magento \Store \Model \WebsiteFactory $ websiteFactory ,
5455 \Magento \Eav \Model \Config $ eavConfig ,
55- $ connectionName = null
56+ $ connectionName = null ,
57+ $ stockConfiguration = null
5658 ) {
5759 parent ::__construct ($ context , $ connectionName );
5860
5961 $ this ->_storeManager = $ storeManager ;
6062 $ this ->_websiteFactory = $ websiteFactory ;
6163 $ this ->eavConfig = $ eavConfig ;
64+ $ this ->stockConfiguration = $ stockConfiguration ?: ObjectManager::getInstance ()
65+ ->get (StockConfigurationInterface::class);
6266 }
6367
6468 /**
@@ -204,7 +208,7 @@ public function getProductCollection($lastEntityId = 0, $limit = 1000)
204208 */
205209 public function addStockStatusToSelect (\Magento \Framework \DB \Select $ select , \Magento \Store \Model \Website $ website )
206210 {
207- $ websiteId = $ this ->getStockConfiguration ()-> getDefaultScopeId ( );
211+ $ websiteId = $ this ->getWebsiteId ( $ website -> getId () );
208212 $ select ->joinLeft (
209213 ['stock_status ' => $ this ->getMainTable ()],
210214 '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
221225 */
222226 public function addStockDataToCollection ($ collection , $ isFilterInStock )
223227 {
224- $ websiteId = $ this ->getStockConfiguration ()-> getDefaultScopeId ();
228+ $ websiteId = $ this ->getWebsiteId ();
225229 $ joinCondition = $ this ->getConnection ()->quoteInto (
226230 'e.entity_id = stock_status_index.product_id ' . ' AND stock_status_index.website_id = ? ' ,
227231 $ websiteId
@@ -255,7 +259,7 @@ public function addStockDataToCollection($collection, $isFilterInStock)
255259 */
256260 public function addIsInStockFilterToCollection ($ collection )
257261 {
258- $ websiteId = $ this ->getStockConfiguration ()-> getDefaultScopeId ();
262+ $ websiteId = $ this ->getWebsiteId ();
259263 $ joinCondition = $ this ->getConnection ()->quoteInto (
260264 'e.entity_id = stock_status_index.product_id ' . ' AND stock_status_index.website_id = ? ' ,
261265 $ websiteId
@@ -277,6 +281,19 @@ public function addIsInStockFilterToCollection($collection)
277281 return $ this ;
278282 }
279283
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+
280297 /**
281298 * Retrieve Product(s) status for store
282299 * Return array where key is a product_id, value - status
@@ -335,18 +352,4 @@ public function getProductStatus($productIds, $storeId = null)
335352 }
336353 return $ statuses ;
337354 }
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- }
352355}
0 commit comments