menu.php (1406B)
1 <?php 2 class ControllerCommonMenu extends Controller { 3 public function index() { 4 $this->load->language('common/menu'); 5 6 // Menu 7 $this->load->model('catalog/category'); 8 9 $this->load->model('catalog/product'); 10 11 $data['categories'] = array(); 12 13 $categories = $this->model_catalog_category->getCategories(0); 14 15 foreach ($categories as $category) { 16 if ($category['top']) { 17 // Level 2 18 $children_data = array(); 19 20 $children = $this->model_catalog_category->getCategories($category['category_id']); 21 22 foreach ($children as $child) { 23 $filter_data = array( 24 'filter_category_id' => $child['category_id'], 25 'filter_sub_category' => true 26 ); 27 28 $children_data[] = array( 29 'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''), 30 'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']) 31 ); 32 } 33 34 // Level 1 35 $data['categories'][] = array( 36 'name' => $category['name'], 37 'children' => $children_data, 38 'column' => $category['column'] ? $category['column'] : 1, 39 'href' => $this->url->link('product/category', 'path=' . $category['category_id']) 40 ); 41 } 42 } 43 44 return $this->load->view('common/menu', $data); 45 } 46 }