How can we achieve below?

if a customer selects options from layered navigation and then goes to a product page, and then back to the category/search view, all of their selections are wiped away. Is there a way to hold those selected options so customers don’t have to re-filter?

How can I set layered navigation filters pro-grammatically?

  • If the user simply clicks browser's back button then he will go to the same page with the same filters enabled. Do you have a custom theme or extension enabled? What you mean exactly by "programmatically". What is the interaction you are trying to accomplish?
    – kbariotis
    Jul 20, 2014 at 19:48

2 Answers 2


You could store the filters in an array in session. Store using the category ID as a key, so that the wrong filters aren't applied when the user visits a different category.

As suggested by @Subesh, you can observe on controller_front_init_before, doing something like the following:

if ($category = Mage::registry('current_category')) {
    $session = Mage::getSingleton('customer/session');
    $categoryFilters = $session->getCategoryFilters() ? $session->getCategoryFilters() : array();

    // Check URL for attribute filters
    $layer = Mage::getSingleton('catalog/layer');
    $filterAttributes = array();
    foreach ($layer->getFilterableAttributes() as $attribute) {
        $value = $this->getRequest()->getParam($attribute->getAttributeCode());
        if ($value) {
            $filterAttributes[$attribute->getAttributeCode()] = $value;

    if (count($filterAttributes) > 0) {
        // Found filter attributes in URL - overwrite filters in session for this category
        $categoryFilters[$category->getId()] = $filterAttributes;
    } elseif (isset($categoryFilters[$category->getId()]) {
        // No filter attributes in URL, but found them in session - apply to URL
        foreach ($categoryFilters[$category->getId()] as $attributeCode => $value) {
            $this->getRequest()->getParam($attributeCode, $value);

Untested, but this should put you in the right direction.


You have to know that the product listed and Layered Navigation (LN) filters that are shown are related. So when you are navigation to some other category lets say (Books) from Shoes Product then you might not have same filters that were available for Shoes.

If you really want them, given that all products across categories are of same type then try taking the filter part of URL ?color=123 to product page and then append the same to URLs when you navigate from product page, which in my opinion would be very "gruesome" task. Or you can observer controller_front_init_before event and get/set the those attribute filter parameters in controllers $_request params.

  • How can I set layered navigation filters programmatically? Mar 21, 2014 at 6:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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