0

This question already has an answer here:

$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.

marked as duplicate by Manoj Deswal, Siarhey Uchukhlebau, Piyush, Prince Patel, liyakat Nov 20 '17 at 11:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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);

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

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