Hide “Out of Stock” Products in Layered Navigation and Product Filter Magento
If you want to filter your product collection and want to show only in stock product than you can do as following.
You need to change in file Mage/Catalog/Model/Layer.php
Change the following function
To
You need to change in file Mage/Catalog/Model/Layer.php
Change the following function
public function prepareProductCollection($collection) { $collection ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes()) ->addMinimalPrice() ->addFinalPrice() ->addTaxPercents() //->addStoreFilter() ->addUrlRewrite($this->getCurrentCategory()->getId()); Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection); return $this; }
To
public function prepareProductCollection($collection) { $collection ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes()) ->addMinimalPrice() ->addFinalPrice() ->addTaxPercents() //->addStoreFilter() ->addUrlRewrite($this->getCurrentCategory()->getId()); Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection); //return $this; $collection->joinField( 'stock_status', 'cataloginventory/stock_status', 'stock_status', 'product_id=entity_id', array( 'stock_status' => Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK, 'website_id' => Mage::app()->getWebsite()->getWebsiteId(), ) ); return $collection; }
Please support us, Like us on Facebook.
Subscribe to:
Post Comments (Atom)
Hi,
ReplyDeleteJust tried this on Magento 1.8 and it didn't seem to work, out of stock sizes in layered navigation still showed up. Any suggestions?
hello,
ReplyDeleteIt doesn't work on 1.8 :(
It is working for me in magento 1.8 as well.
DeleteThank you very much, this worked for me on 1.8
ReplyDeleteThanks a lot. Works for me on 1.8 CE.
ReplyDeleteHello Patel,
ReplyDeletethe problem is that I use configurable products, at the Layered navigation a sea the simple product option, but when i open a configurable its not available!
Show products out of Stock is ON
Alow reorder is OFF
Its possible to hide those products from the layered navigation that aren't in stock.
Thank you,
Best regards
Scamp
Not working
ReplyDelete