Jump to content

Customize block categories


kpl

Recommended Posts

Lets assume I have a category tree four or more levels deep:

 

Level 1 - root

Level 2 - main categories

Level 3,4... - subcats

 

What I want to achieve is to have category tree displayed in this way:

 

Level 1 - no category block displayed (done)

Level 2 - show selected main category full tree

Level 3,4... - show the same as level 2 - selected main category full tree

 

What I know is that I have to modify blockategories.php file ad play with lines 184-190 to make it work. The problem I have is propably simple - instead of current or nearest parent category id, I should pass the value of Level 2 parent category id. But I don't know how to get this id...

 

For the time being, I made it in the worst possible, non flexible way:

 

if($category->id=='9' || $category->id=='10' || $category->id=='11' || $category->id=='36') {
                    $category->id_parent=3;
                }

 

So this works only as long, as current category structure is kept.

I need flexible solution for assigning correct " $category->id_parent=???".

 

Thanks in advance!

Link to comment
Share on other sites

What levels do you mean? That code returns a level 2 parent for any category.
$category is a category object that you already have, $id_parent is a result that you can use later.

I used $id_parent as a result in the previous code for illustration, try this one instead:

foreach ($category->getParentsCategories() as $cat)
{
     if($cat['level_depth'] == 2)
     {
         $category->id_parent = $cat['id_category'];
         break;
     }
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...