Search in stock products in Magento

Posted: January 17, 2015 in How To?, Magento
Tags:

Want to setup a checkbox in advanced search for in stock products?

  1. Add the checkbox to the advanced search page (name ‘stock’ to the checkbox)
  2. Clone file /app/code/Mage/CatalogSearch/Model/Advance.php to /app/code/local/Mage/CatalogSearch/Model/Advance.php
  3. In the new file add to function prepareProductCollection the following code (before the return $this; statement)
    if (Mage::app()->getRequest()->getParam('stock')) {
    Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
    }

For the regular search box:

  1. Add the checkbox to the search block (name ‘stock’ to the checkbox)
  2. Clone file /app/code/Mage/CatalogSearch/Model/Layer.php to /app/code/local/Mage/CatalogSearch/Model/Layer.php
  3. In the new file add to function prepareProductCollection the following code (before the return $this; statement)
    if (Mage::app()->getRequest()->getParam('stock')) {
    Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s