category.php (2065B)
1 <?php 2 class ControllerExtensionModuleCategory extends Controller { 3 public function index() { 4 $this->load->language('extension/module/category'); 5 6 if (isset($this->request->get['path'])) { 7 $parts = explode('_', (string)$this->request->get['path']); 8 } else { 9 $parts = array(); 10 } 11 12 if (isset($parts[0])) { 13 $data['category_id'] = $parts[0]; 14 } else { 15 $data['category_id'] = 0; 16 } 17 18 if (isset($parts[1])) { 19 $data['child_id'] = $parts[1]; 20 } else { 21 $data['child_id'] = 0; 22 } 23 24 $this->load->model('catalog/category'); 25 26 $this->load->model('catalog/product'); 27 28 $data['categories'] = array(); 29 30 $categories = $this->model_catalog_category->getCategories(0); 31 32 foreach ($categories as $category) { 33 $children_data = array(); 34 35 if ($category['category_id'] == $data['category_id']) { 36 $children = $this->model_catalog_category->getCategories($category['category_id']); 37 38 foreach($children as $child) { 39 $filter_data = array('filter_category_id' => $child['category_id'], 'filter_sub_category' => true); 40 41 $children_data[] = array( 42 'category_id' => $child['category_id'], 43 'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''), 44 'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']) 45 ); 46 } 47 } 48 49 $filter_data = array( 50 'filter_category_id' => $category['category_id'], 51 'filter_sub_category' => true 52 ); 53 54 $data['categories'][] = array( 55 'category_id' => $category['category_id'], 56 'name' => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''), 57 'children' => $children_data, 58 'href' => $this->url->link('product/category', 'path=' . $category['category_id']) 59 ); 60 } 61 62 return $this->load->view('extension/module/category', $data); 63 } 64 }