0

in a shop we have the usual main Navigation, which outputs the url as a clean url-rewrite url, eg: /category-one/sub-category-one/

Now if I click into the first category /category-one and use the layered navigation in the sidebar to get to the sub-category, the URL Link is written as:

/category-one?cat=2 rather than the clean urls version from the main menu: /category-one/sub-category-one/

Why is this and how do I change this?

In the code the url is rendered using:

echo $this->getCategoryUrl($_category)

and in the main navi it is rendered with:

$child->getUrl()

1 Answer 1

3

It's because you aren't actually viewing that category, you are view category-one filtering the products by only products that are in sub-category-one. Whilst this might sound like a pedantic difference, there are multiple reasons they aren't the same thing. Layout handles applied will be those matching category-one not sub-category-one for example. The same applies for all settings/attributes that can be modified on a category level, such as theme. If sub-category-one wasn't a category with is_anchor enabled, then by your approach, clicking it would mean the layered navigation disappears, whereas it doesn't with the current implementation.

There is no core functionality to support what you are trying to achieve, however you could potentially modify the code if you are happy with the above effects. The simplest way would probably be to rewrite Mage_Catalog_Model_Layer_Filter_Item::getUrl and do something like:

if ($this->getFilter()->getRequestVar() === 'cat') {
    return Mage::getModel("catalog/category")->load($this->getValue())->getUrl();
}
return parent::getUrl();

Though I doubt this is massively efficient.

1
  • Thanks @Cags! I wasn't thinking straight, else I would have realised that it is a filter and not a link to the category. Doh!
    – tecjam
    Commented Mar 16, 2015 at 15:28

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.