0
$productCollection = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToSelect('author')
    ->addAttributeToFilter('author', array('like' => $searchstring.'%'))
    ->setPage($pageid, $resultcount);

above given is my search custom code. Please let me know how to only add in stock product using the above code.

  • what version of Magento? – jscar Nov 17 '17 at 8:07
0

Add below code at the end of the line.

Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection);

| improve this answer | |
0

Please use this

$productCollection = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToSelect('author')
    ->addAttributeToFilter('author', array('like' => $searchstring.'%'))
    ->setPage($pageid, $resultcount);
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection);

Thanks

| improve this answer | |

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