/** * */ public function get_sort_categories_children($parentId, $levels, $cur_level = 0) { $res_ar = array(); $Product = new Product(); if ($levels > 0) { //$sel = $this->select()->from(array('a' => $this->_name,)->where('parentId='.$parentId); $children = parent::fetchAll('parentId=' . $parentId)->toArray(); //$children = parent::fetchAll($sel)->toArray(); //$children = $this->getAll(array('where' => 'a.parentId='.$parentId)); //print_r($children);exit; foreach ($children as $key => $child) { $child['level'] = $cur_level; $ar_children = $this->get_sort_categories_children($child['id'], $levels - 1, $cur_level + 1); if (count($ar_children) <= 0) { $product_count = $Product->getProductCount($child['children']); $child['c_count'] = $product_count; } else { $c = 0; foreach ($ar_children as $one_child) { $c += $one_child['c_count']; } $child['c_count'] = $c; } if ($child['c_count'] > 0) { $res_ar[] = $child; } $res_ar = array_merge($res_ar, $ar_children); } } return $res_ar; }