Reputation: 61
Is there a way, or an extension, that will modify the Category module so it only displays the current top level category page's sub-categories.
For example, if I am on the "Laptops & Desktops" category page, the sidebar module would only list the sub-categories associated with "Laptops & Desktops" category, such as "Macs" and "PCs" with the main heading "Laptops & Desktops" (And not list or show any of the other top level categories).
Upvotes: 1
Views: 5600
Reputation: 4128
Update the foreach
section in catalog/controller/module/category.php
in the following way to show only the sub-categories in left column.
$cur_category_id = $this->data['category_id']; // new code
foreach ($categories as $category) {
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
if($cur_category_id && $cur_category_id == $category['category_id']){
$this->data['heading_title'] = $category['name'];
$this->data['categories'][] = array(
'category_id' => $child['category_id'],
'children' => array(),
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
}
$data = array(
'filter_category_id' => $category['category_id'],
'filter_sub_category' => true
);
/*
$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($data) . ')' : ''),
'children' => $children_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
); */
}
Note: As I added comment to your question earlier, only the sub categories will be shown and there will not be any option to select the products added to parent categories.
Have a nice day :) !!
Upvotes: 1