Jump to content

Set a default image on each level of ps_categorytree module


pabloMarch

Recommended Posts

Hello people,

I'm trying to get the "level_depth" of all subcategories to set a custom image for each level depends of the depth on the left menu but it return me the current position of that specific query and not the real depth of the category, example of what I have:

* RootCategory (shows backoffice image)
  |_ 2ndLevelCategory (shows backoffice image)
     |_ 3rdLevelCategory (shows generic image from tpl)
        |_4thLevelCategory (shows generic image from tpl)
* RootCategory (shows backoffice image)
  |_ 2ndLevelCategory (shows backoffice image)
     |_ 3rdLevelCategory (shows generic image from tpl)
        |_4thLevelCategory (shows generic image from tpl)
* ...

 

I tried passing the $category variable on the module method of "ps_categorytree.tpl" like this:
 

<?php
...
public function getTree($resultParents, $resultIds, $maxDepth, $id_category = null, $CATEGORY, $currentDepth = 0)
{
    if (is_null($id_category)) {
        $id_category = $this->context->shop->getCategory();
    }

    $children = [];

    if (isset($resultParents[$id_category]) && count($resultParents[$id_category]) && ($maxDepth == 0 || $currentDepth < $maxDepth)) {
        foreach ($resultParents[$id_category] as $subcat) {
            $children[] = $this->getTree($resultParents, $resultIds, $maxDepth, $subcat['id_category'], $currentDepth + 1);
        }
    }

    if (isset($resultIds[$id_category])) {
        $link = $this->context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']);
        $name = $resultIds[$id_category]['name'];
        $desc = $resultIds[$id_category]['description'];
    } else {
        $link = $name = $desc = '';
    }

    return [
        'id' => $id_category,
        'link' => $link,
        'name' => $name,
        'desc'=> $desc,
      	'categoryroot'=>$CATEGORY,
        'children' => $children
    ];
}

Notice the parameter $CATEGORY but it only returns the main category and not the children.

Thanks in advance for any help you can provide me.

Pablo

Link to comment
Share on other sites

  • pabloMarch changed the title to Set a default image on each level of ps_categorytree module

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...