Skip to content

Magento2 Catalog widget in-stock filter not working

I added stock availability dropdown to “catalog product list” and added following code in MagentoCatalogWidgetBlockProduct/ProductsList.php I tried following code:

public function createCollection()
    {
        $collection = $this->getBaseCollection();

        $collection->setVisibility($this->catalogProductVisibility->getVisibleInCatalogIds());
        $collection->getSelect()
        ->join(['stock_item'=>'cataloginventory_stock_item'], 
            'e.entity_id=stock_item.product_id and stock_item.qty>0',
            []
        );
        return $collection;
    }

Also, tried:

public function createCollection()
    {
        $collection = $this->getBaseCollection();

        $collection->setVisibility($this->catalogProductVisibility->getVisibleInCatalogIds());
        $this->_stockHelper->addInStockFilterToCollection($collection);
        return $collection;
    }

But none of above code is working
Note: This is core file making canges directly to experiment only once it will work, i will override it

enter image description here