In magento-1.9 I would call
$Products = Mage::getResourceModel('catalog/product_collection');
$products->setFlag('require_stock_items', true);
And this would add the StockItem
to every product in the collection.
I can’t see how to do this in M2, if I instantiate a MagentoCatalogModelResourceModelProductCollectionFactory
and call MagentoCatalogInventoryModelResourceModelStockStatus->addStockDataToCollection
it will error out with
"0": "You cannot define a correlation name 'stock_status_index' more than once",
"1": "#1 Magento\Framework\DB\Select->_join() called at [vendor/magento/zendframework1/library/Zend/Db/Select.php:357]n#2 Zend_Db_Select->joinInner() called at [vendor/magento/zendframework1/library/Zend/Db/Select.php:336]
I don’t have MSI installed, as I understand it’s still optional?