1

we would like to Set a selected filter on initial page load for a category.

For example: when accessing the category, shoe_size=10 should already be selected

I read you can access the variables quite easily here

But how do I

  • pass a variable to the code? (can this be done through a custom layout update in category xml in backend)?
  • But more importantly. How do I SET the shoe_size filter to value 10 in code? Is there a setFilter()?

Help appreciated

3

The values for the layered nav filter are retrieved from the request ($_GET). you can try to use an observer for controller_action_predispatch_catalog_category_view where you check if you are on the correct category (and other conditions if you have any) and try to set a value in the request.
Something like this:

public function setDefaultFilter($observer) 
{
    if (your conditinos here) {
        Mage::app()->getRequest()->setParam('shoe_size', 10);
    }
}
| improve this answer | |
  • That sounds great Marius'. Super. And could I pass the variables from custom layout update too? (And grab them) – snh_nl Feb 11 '15 at 16:37
  • Thanks a ton Marius, I was looking for this solution from a long long time – Akshay Jindal Jul 25 '16 at 5:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.