$show_sub = ''; // neu la sub cat if ($cat_slug != '') { $select_node = ProductCategory::bll()->getOneBySlug($cat_slug); if ($select_node) { $in_sub = true; $selected_node_id = $select_node['id']; if ($select_node['level'] == 1) { //get childs next to current $selected_parent_slug = $select_node['slug']; //$childs = $select_node->getNode()->getChildren(); $childs = ProductCategory::getNodeChildrens($selected_node_id); } else { //get from bottom to top //$parents = $select_node->getNode()->getAncestors(); $parents = ProductCategory::getSinglePath($selected_node_id); //print_r($parents->toArray()); if (count($parents) >= 2) { $p = $parents[1]; } else { $p = $parents[0]; } $selected_parent_slug = $p['slug']; $hops = intval($select_node['level']) - intval($p['level']); //echo "level 2:".count($parents).":".$hops; //print_r($p->toArray()); //$childs = $p->getNode()->getDescendants($hops); $childs = ProductCategory::getNodeChildrens($p['id'], $hops, $select_node['id']); } //build sub into html $show_sub = ProductCategory::buildTree($childs);