CMS Magento Mastering Development

How to filter product by stock quantity?

I am trying to get results of products by stock quantity filter

i use this inside the constructor of my helper class.

 \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $product_lib

The question is how do i add stock quantity from and to in this?

addCategoriesFilter(array('in' => array(1,2,3))->
addFieldToFilter('price', ['from' => $min_price, 'to' => $max_price])

When i try to additional addFieldToFilter with quantity it says not found. What i am looking for is to achieve the same results as in catalog->products filter.

Any suggestion is helpful.
Also if possible can you suggest where to do i look for these kinds of information? Is there any book that would be helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *