-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
Setting the value of 'Display Out of Stock Products' in the backend to 'No' does not have the effect desired. If you set this to 'No' you would expect that only products that are in stock are shown.
Preconditions
- PHP7.0
- Checked in both MG2.1.3 CE and MG2.1.4 CE
Steps to reproduce
- Create a configurable product and set itself and all associated simples to out of stock
- Set the value for 'Display Out of Stock Products' to 'No' in the store configuration
- Go to a product list containing your configurable product
Expected result
- The configurable product should not be shown
Actual result
- The configurable product is shown
We traced this issue back to Magento\CatalogInventory\Helper\Stock.
In the function addIsInStockFilterToCollection a flag check is done on 'require_stock_items'. Because this flag is never set or used in Magento (wtf!), it causes the second parameter in addStockDataToCollection to always be false. This has the undesired effect that out of stock products are shown...
public function addIsInStockFilterToCollection($collection)
{
$stockFlag = 'has_stock_status_filter';
if (!$collection->hasFlag($stockFlag)) {
$isShowOutOfStock = $this->scopeConfig->getValue(
\Magento\CatalogInventory\Model\Configuration::XML_PATH_SHOW_OUT_OF_STOCK,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
$resource = $this->getStockStatusResource();
$resource->addStockDataToCollection(
$collection,
!$isShowOutOfStock && $collection->getFlag('require_stock_items')
);
$collection->setFlag($stockFlag, true);
}
}
It is our opinion that the '&& $collection->getFlag('require_stock_items')' should be removed as it is never set or referenced in the entire Magento project. Removing this part also fixes the fact the out-of-stock products are shown