$current_category = $dbtree->CheckParent($GLOBALS['Rewrite'], array('id_category')); if (!$current_category || empty($current_category)) { header('Location: /404/'); exit; } $GLOBALS['CURRENT_ID_CATEGORY'] = $id_category = $current_category['id_category']; $subcats = $dbtree->GetSubCats($id_category, array('id_category', 'category_level', 'name', 'translit', 'pid', 'visible')); foreach ($subcats as &$s) { $s['subcats'] = count($dbtree->GetSubCats($s['id_category'], 'all')); } $tpl->Assign('subcats', $subcats); $GLOBALS['current_categories'] = GetParents((int) $id_category); $GLOBALS['GLOBAL_CURRENT_ID_CATEGORY'] = isset($GLOBALS['current_categories']) && is_array($GLOBALS['current_categories']) ? end($GLOBALS['current_categories']) : 0; } // print_r(G::getmicrotime() - $s_time);die(); $navigation = $dbtree->GetCategories(array('id_category', 'category_level', 'name', 'translit', 'category_img', 'pid'), 1); foreach ($navigation as &$l1) { $level2 = $dbtree->GetSubCats($l1['id_category'], 'all'); foreach ($level2 as &$l2) { $level3 = $dbtree->GetSubCats($l2['id_category'], 'all'); $l2['subcats'] = $level3; } $l1['subcats'] = $level2; } $tpl->Assign('navigation', $navigation); unset($current_category, $subcats, $level2, $level3, $id, $res, $id_category); function GetSubCategories($id_category) { return true; } function GetParents($id_category, $parents = false)
public function navigation($idsegm) { $dbtree = new dbtree(_DB_PREFIX_ . 'category', 'category', $this->db); //Достаем категории 1-го уровня $navigation = $dbtree->GetCategories(array('id_category', 'category_level', 'name', 'translit', 'pid'), 1); //Перебираем категории 2-го и 3-го уровня, отсекая ненужные $needed = $dbtree->GetCatSegmentation($idsegm); foreach ($navigation as $key1 => &$l1) { $level2 = $dbtree->GetSubCats($l1['id_category'], 'all'); foreach ($level2 as $key2 => &$l2) { $level3 = $dbtree->GetSubCats($l2['id_category'], 'all'); foreach ($level3 as $key3 => &$l3) { if (!in_array($l3['id_category'], $needed)) { unset($level3[$key3]); } } if (in_array($l2['id_category'], $needed) || !empty($level3)) { $l2['subcats'] = $level3; } else { unset($level2[$key2]); } } if (in_array($l1['id_category'], $needed) || !empty($level2)) { $l1['subcats'] = $level2; } else { unset($navigation[$key1]); } } return $navigation; }
$image = $Products->GetPhotoById($l['id_product']); $list1[] = array('id_product' => $l['id_product'], 'art' => $l['art'], 'img_1' => $l['img_1'], 'image' => $image[0]['src'], 'name' => $l['name'], 'note' => $l['note'], 'min_mopt_qty' => $l['min_mopt_qty'], 'inbox_qty' => $l['inbox_qty'], 'price_mopt' => $l['price_mopt'], 'price_opt' => $l['price_opt'], 'units' => $l['units'], 'opt_correction_set' => $l['opt_correction_set'], 'mopt_correction_set' => $l['mopt_correction_set']); } $list = $list1; } else { foreach ($price_list as $k => &$l) { if (!isset($name)) { $name = $l['price_name']; } $image = $Products->GetPhotoById($l['id_product']); $list1[$l['id_category']]['name'] = $l['cat_name']; $list1[$l['id_category']]['products'][] = array('id_product' => $l['id_product'], 'art' => $l['art'], 'img_1' => $l['img_1'], 'image' => $image[0]['src'], 'name' => $l['name'], 'note' => $l['note'], 'min_mopt_qty' => $l['min_mopt_qty'], 'inbox_qty' => $l['inbox_qty'], 'price_mopt' => $l['price_mopt'], 'price_opt' => $l['price_opt'], 'units' => $l['units'], 'opt_correction_set' => $l['opt_correction_set'], 'mopt_correction_set' => $l['mopt_correction_set']); $i++; } $fields = array('id_category', 'name', 'pid', 'category_level'); $var1 = $dbtree->GetCategories($fields, 1); foreach ($var1 as $v1) { $list[$v1['id_category']] = $v1; foreach ($dbtree->GetSubCats($v1['id_category'], $fields) as &$v2) { if (isset($list1[$v2['id_category']])) { $v2['products'] = $list1[$v2['id_category']]['products']; } foreach ($dbtree->GetSubCats($v2['id_category'], $fields) as &$v3) { if (isset($list1[$v3['id_category']])) { $v3['products'] = $list1[$v3['id_category']]['products']; $v2['subcats'][$v3['id_category']] = $v3; } } if (isset($v2['subcats']) == true || isset($v2['products']) == true) { $list[$v2['pid']]['subcats'][$v2['id_category']] = $v2; }