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()

I have found above code to get related product collection. How can I filter this collection by is_salable?

1 Answer 1


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() method

 * @return $this
protected function _prepareData()
    $product = $this->_coreRegistry->registry('product');
    /* @var $product \Magento\Catalog\Model\Product */

    $this->_itemCollection = $product->getRelatedProductCollection()->addAttributeToSelect(

    if ($this->moduleManager->isEnabled('Magento_Checkout')) {


    foreach ($this->_itemCollection as $product) {

    return $this;

So, I'd rewrite Magento\Catalog\Block\Product\ProductList\Related & use addInStockFilterToCollection(), as explained in the quoted answer


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.