I am having an issue. I need to show the sub-category layered navigation on the SUBCATEGORY page of a store that I am working on. You guys already know that on the subcategory layered navigation is already shown on the MAIN Category page(s). Please understand that I want it to show on both the Category(s) and Sub-Category(s) pages. Please view the images to see what I have already.
Main Category Page!
Main Category Layered navigation
Sub Category Page! with Layered Navigation (Limited sub category list)
Sub Category Layered Navigation (Limited list)
But to in getting the limited sub category layered navigation I tried this:
https://stackoverflow.com/questions/8795810/magento-showing-sibling-categories-in-layered-navigation
All I need is help with is editing:
app/code/core/Mage/Catalog/Model/Layer/Filter/Category.php
For this line of code to show the full sub category on the sub category page and highlight the current/active category
if(count($categoty->getChildrenCategories())){
$categories = $categoty->getChildrenCategories();
}else{
$categories = $categoty->getParentCategory()->getChildrenCategories();
}
Best Answer
As you already know the real category filtering is taking place in
app/code/core/Mage/Catalog/Model/Layer/Filter/Category.php
, more specifically in_getItemsData()
. Let us inspect that method.As you can see, the method loads child categories of
$categoty
in layered navigation filter. That means we need to set this variable to a parent category in level 2 (Every main categories lies in level 2), according to the current category that we stands.We can achieve this in many ways. In my method, I dig into the codes further and find the exact position where the category is set for layered navigation.
It resides here
app/code/core/Mage/Catalog/Model/Layer.php
ingetCurrentCategory()
. The method look like this.In short, it loads the current category to the variable
$categoty
(variable that I mentioned in_getItemsData()
) if it set, otherwise loads theroot-category
to variablecategoty
. Replace this method with this codeWhat we are doing here is, we get the parent category in level 2 from the current category and set it to
$categoty
, so that we can see all child categories in layered navigation.As I already mentioned, you can achieve it in many ways. All you need to do is to set
$categoty
variable with parent category in level 2. Above I have altered the root files. It is not a good practice. You have to create a module that rewrites the model fileapp/code/core/Mage/Catalog/Model/Layer.php
and then overwrite the methodgetCurrentCategory()
.Hope it helps