0

How to get products which inventory is greater than 0 and "In Stock" (inventory and In Stock attribute is set in Admin panel)

This is my current code

$_productCollection = $product->getCollection()->addAttributeToSelect('*')
                                    ->addAttributeToFilter('visibility', 4) // Only catalog, search visiblity
                                    ->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED))
                                    ->setCurPage(1)
                                    ->setPageSize(12);

What condition should i add to get what i want?

3
  • 1
    By default, magento displays product which has inventory greater than zero and is set to "in stock". Other product won't display Aug 1, 2014 at 15:22
  • So you mean that my code above will already retrieve only products with inventory greater than zero and is set to "in stock"?
    – Bogz
    Aug 2, 2014 at 3:36
  • if it helped you, accept it as answer. Othrewise post your own answer and feel free to accept it. Aug 3, 2014 at 10:18

1 Answer 1

1

To know whether product is in stock or not, you can use isInStock().

   $id = 24 //product id
   $_product = Mage::getModel('catalog/product')->load($id);

   //check whether product is in stock
   if($_product->isInStock()){

       //do some stuff here
   }

You can display | hide products without inventory in front-end through admin.For this..

  1. Go to System ->Configuration.

  2. Select appropriate scope.

  3. Select inventory tab under CATALOG

  4. There you have an option to set this

enter image description here

Hope it helps

1
  • This doesn't answer the question (which was about filtering a collection)
    – xtx
    Apr 23, 2020 at 14:05

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.