Magento – Magento – set default filter in layered navigation

magento-1.8

I need some help with the following issue. I use an attribute in the layered navigation which is connected to stock values. The attribute has two options – In stock and All products (which includes out of stock products as well).

Is there any way I can have the In stock option selected by default when an user enters a category page? This way users would view only products which are in stock, but if they want they can select all products and also view the others.

Best Answer

You need to update catalog/layer/filer/atribute.php model , method apply in the following way:

0) check the attribute code, if the code is our filter, continue

1) if the url is empty, we assume in stock is selected

2) you also need custom logic for the link "clear" and "clear all" in the catalog/layer/filer/item.php model