Related products are showing with out of stock products, I want to hide out of stock products from related products only.
$this->_itemCollection = $product->getRelatedProductCollection()
->addAttributeToSelect('required_options')
->setPositionOrder()
->addStoreFilter();
I have found above code to get related product collection. How can I filter this collection by is_salable
?
Best Answer
Have you tried something like this? https://magento.stackexchange.com/a/130070/3566
Not sure if this could be achieved with a plugin approach, setting a aroundGetItems plugin, after would not be an option, as collection is loaded in
_prepareData()
methodSo, I'd rewrite Magento\Catalog\Block\Product\ProductList\Related & use
addInStockFilterToCollection()
, as explained in the quoted answer