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.

1
  • what version of Magento?
    – jscar
    Commented Nov 17, 2017 at 8:07

2 Answers 2

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.