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?
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..
Go to System ->Configuration
.
Select appropriate scope.
Select inventory
tab under CATALOG
There you have an option to set this
Hope it helps