Bueno
Bueno

Reputation: 1950

Magento - Add default filter to product collection

Working with a client who saw this site and would like something similar.

http://www.boylstontradingco.com/shop/sale

As you can see when you browse to the "sale" category a "sale" filter is activated by default in the layered navigation on the left. I know that part of the layered navigation pulls its info from a function called getActiveFilters(). Is there a way to add an active filter by default in the code or through the admin? Any help would be much appreciated.

Thanks!

Upvotes: 2

Views: 3045

Answers (1)

Tim Bezhashvyly
Tim Bezhashvyly

Reputation: 9100

Quite easy:

$model = Mage::getModel('catalog/layer_filter_category');
$item = Mage::getModel('catalog/layer_filter_item');
$model->getLayer()->getState()->addFilter(
  $item->setFilter($model)
       ->setLabel('Sale')
);

Upvotes: 2

Related Questions