Page 3 of 4
Re: Subcatagory
Posted: Tue Jan 10, 2012 1:35 am
by lukinhasb
How to use this solution on OpenCart 1.5.1?
Code: Select all
if (substr_count($new_path, '_') < 1) {
$children = $this->getCategories($result['category_id'], $new_path);
}
category.php
Code: Select all
<?php
class ControllerModuleCategory extends Controller {
protected function index() {
$this->language->load('module/category');
$this->data['heading_title'] = $this->language->get('heading_title');
if (isset($this->request->get['path'])) {
$parts = explode('_', (string)$this->request->get['path']);
} else {
$parts = array();
}
if (isset($parts[0])) {
$this->data['category_id'] = $parts[0];
} else {
$this->data['category_id'] = 0;
}
if (isset($parts[1])) {
$this->data['child_id'] = $parts[1];
} else {
$this->data['child_id'] = 0;
}
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$this->data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
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
);
$product_total = $this->model_catalog_product->getTotalProducts($data);
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'] . ' (' . $product_total . ')',
'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
);
$product_total = $this->model_catalog_product->getTotalProducts($data);
$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'] . ' (' . $product_total . ')',
'children' => $children_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/category.tpl')) {
$this->template = $this->config->get('config_template') . '/template/module/category.tpl';
} else {
$this->template = 'default/template/module/category.tpl';
}
$this->render();
}
}
?>
I don't know much PHP, I've tried to mess around with the code but couldn't find... I've discovered it has something to do with this part of the code though:
Code: Select all
if (isset($this->request->get['path'])) {
$parts = explode('_', (string)$this->request->get['path']);
} else {
$parts = array();
}
It seems this part controls when the category will expand, dtk much lol

Re: Subcatagory
Posted: Tue Jan 10, 2012 9:45 pm
by Qphoria
What are you trying to do? You want all categories to be expanded?
Re: Subcatagory
Posted: Tue Jan 10, 2012 10:13 pm
by lukinhasb
Yes.
Re: Subcatagory
Posted: Wed Jan 11, 2012 7:20 am
by arturhaddad
I need this solution too.
Thanks,
tsefeiso
Re: Subcatagory
Posted: Thu Jan 12, 2012 10:56 pm
by Qphoria
Try this...
1. EDIT: catalog/view/theme/default/template/modele/category.tpl
2. FIND:
Code: Select all
<?php if ($category['children']) { ?>
<ul>
3. REPLACE WITH:
Code: Select all
<?php if ($category['children']) { ?>
<ul style="display:block">
Re: Subcatagory
Posted: Fri Jan 13, 2012 1:04 am
by lukinhasb
It works, thanks a lot!!!!!!!!!!!
Re: Subcatagory
Posted: Wed Feb 01, 2012 9:49 pm
by avriukas
Hello Guys,
How to solve this problem on 1.5.1.3 ?
this code not enought -
<?php if ($category['children']) { ?>
<ul style="display:block">
when I do in this way - all what I get - is always show all subcategories in the tree, but this not resolve subcategory of subcategory not show problem
Subcategories of subcategory not shown in category tree

Desktops > TEST (TEST subcategory) SHOW)
Desktops > TEST > TEST2 (TEST2 subcategory- NOT SHOW)
Thanx alot !
Re: Subcatagory
Posted: Fri Feb 03, 2012 6:08 pm
by wowo
is there any fix to this?
More than that - does sub-sub-category keyword work? It does not for me.
Keyowrds are shown ok for parent and subcategory, but not for sub-sub category.
Is that the feature or bug? Is there any solution to this?
Re: Subcatagory
Posted: Fri Feb 03, 2012 6:44 pm
by wowo
NO Sub-sub-category kewords.
It looks like it doesnt work for default intall too.
Can anyone confirm if this is working for them?
Re: Subcatagory
Posted: Sun Feb 05, 2012 1:44 am
by wowo
up.
anyone?
Re: Subcatagory
Posted: Tue Feb 07, 2012 3:17 pm
by wowo
up
Re: Subcatagory
Posted: Wed Feb 22, 2012 3:16 am
by dmonco
Hi! I brought categories and subcategories to the home page. You can see here
http://technolife.net.ua
The problem that there are too much subcategories for some categories. I decided to slice them till 10 for subcategory. Could anyone help me?
P.S. I think I should use array_slice somehow but frankly my knowledges are very poor.
My file controller/categoryhome.php
Code: Select all
<?php
class ControllerModulecategoryhome4 extends Controller {
protected $category_id = 0;
protected $path = array();
protected function index() {
$this->language->load('module/categoryhome4');
$this->data['heading_title'] = $this->language->get('heading_title');
$this->load->model('catalog/category');
$this->load->model('tool/image');
if (isset($this->request->get['path'])) {
$this->path = explode('_', $this->request->get['path']);
$this->category_id = end($this->path);
}
$url = '';
$this->data['categoryhome4'] = $this->getCategories($this->config->get('categoryhome4_category'));
$this->id = 'categoryhome4';
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/categoryhome4.tpl')) {
$this->template = $this->config->get('config_template') . '/template/module/categoryhome4.tpl';
} else {
$this->template = 'default/template/module/categoryhome4.tpl';
}
$this->render();
}
//dymm
protected function getCategories($parent_id, $current_path = '',$stop = false) {
$categoryhome4 = array();
$category_id = array_shift($this->path);
$results = $this->model_catalog_category->getCategories($parent_id);
$i=0;
foreach ($results as $result) {
if (!$current_path)
{
$new_path = $result['category_id'];
}
else
{
$new_path = $current_path . '_' . $result['category_id'];
}
if ($this->category_id == $result['category_id']) {
$categoryhome4[$i]['href'] = $this->url->link('product/category', 'path=' . $new_path);
} else {
$categoryhome4[$i]['href'] = $this->url->link('product/category', 'path=' . $new_path);
}
if ($result['image']) {
$image = $result['image'];
} else {
$image = 'no_image.jpg';
}
$categoryhome4[$i]['thumb'] = $this->model_tool_image->resize($image, 110, 110);
$categoryhome4[$i]['name'] = $result['name'];
//dymm ------------------>
if(!$stop)
$categoryhome4[$i]['subcats'] = $this->getCategories($result['category_id'],$new_path,true);
//dymm <------------------
$i++;
}
return $categoryhome4;
}
}
?>
Re: Subcatagory
Posted: Fri Feb 24, 2012 1:05 am
by dmonco
SO? Anybody knows??
Re: Subcatagory
Posted: Sat Feb 25, 2012 12:02 pm
by dmonco
So, I resolved my problem by myself.
I added this
after this
Code: Select all
//dymm ------------------>
if (!$stop)
$categoryhome4[$i]['subcats'] = $this->getCategories($result['category_id'], $new_path, true);
//dymm <------------------
$i++;
Everything works fine.
Re: Subcatagory
Posted: Fri Aug 24, 2012 12:45 am
by mifzal.mufthi
TAurus wrote:WeNDoR wrote:please, coul someone tell me how to solve this problem ? I need the caregories to be expanded as default (if they have subcategories)
open catalog\controller\module\category.php
and replace
Code: Select all
if ($category_id == $result['category_id']) {
$children = $this->getCategories($result['category_id'], $new_path);
}
with
Code: Select all
//if ($category_id == $result['category_id']) { //hack to display all subcategories
$children = $this->getCategories($result['category_id'], $new_path);
//}
I don't find the following code in my catalog\controller\module\category.php file
Code: Select all
if ($category_id == $result['category_id']) {
$children = $this->getCategories($result['category_id'], $new_path);
}
however, I find the following code
Code: Select all
<?php
class ControllerModuleCategory extends Controller {
protected function index($setting) {
$this->language->load('module/category');
$this->data['heading_title'] = $this->language->get('heading_title');
if (isset($this->request->get['path'])) {
$parts = explode('_', (string)$this->request->get['path']);
} else {
$parts = array();
}
if (isset($parts[0])) {
$this->data['category_id'] = $parts[0];
} else {
$this->data['category_id'] = 0;
}
if (isset($parts[1])) {
$this->data['child_id'] = $parts[1];
} else {
$this->data['child_id'] = 0;
}
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$this->data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
$total = $this->model_catalog_product->getTotalProducts(array('filter_category_id' => $category['category_id']));
$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
);
$product_total = $this->model_catalog_product->getTotalProducts($data);
$total += $product_total;
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $total . ')' : ''),
'children' => $children_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/category.tpl')) {
$this->template = $this->config->get('config_template') . '/template/module/category.tpl';
} else {
$this->template = 'default/template/module/category.tpl';
}
$this->render();
}
}
?>
Re: Subcatagory
Posted: Wed Oct 24, 2012 11:13 pm
by SuporteOn
In Opencart 1.5.4.1, you do expand subcategories in CSS, by editing the file \catalog\view\theme\default\stylesheet\stylesheet.css.
Replaces this code (lines 742-744)
Code: Select all
.box-category > ul > li ul {
display: none;
}
by this one
Code: Select all
.box-category > ul > li ul {
display: block;
}
________________________________________________________________________________________________
<new> Opencart 1.5.4.1 Override is an Opencart extension designed by
SuporteOn that allows you to override your entire store (Classes, Files and Folders, Controller, View, Templates, Model, CSS, JS) in a separate folder, without changing the original files. It is an alternative for vQmod. With this extension, you edit files directly with your favorite PHP Editor, as you always did.
Re: Subcatagory
Posted: Sat Oct 27, 2012 7:18 am
by fontez
i have in my code: (module category accordion)
category_accordion.php
Code: Select all
protected function loadCategories($parent_id, $current_path = '', $cid = '') {
$category_id = array_shift($this->path);
$this->getCategoriesFromdb($category_id);
$results = $this->model_catalog_category->getCategories($parent_id);
$ret_string = '';
if ($results) {
if ($parent_id == 0) {
$ret_string .= '<ul id="cat_accordion">';
} else {
$ret_string .= '<ul>';
}
}
foreach ($results as $result) {
if (!$current_path) {
$new_path = $result['category_id'];
} else {
$new_path = $current_path . '_' . $result['category_id'];
}
$ret_string .= '<li class="cid' . $result['category_id'] . '">';
$children = '';
$children = $this->loadCategories($result['category_id'], $new_path);
appear all categories and subcategories.
i try change:
Code: Select all
$results = $this->model_catalog_category->getCategories($parent_id);
to:
Code: Select all
$results = $this->model_catalog_category->getCategories($category_id);
and error. how change for appear only sub-categories by category active?
Re: Subcatagory
Posted: Tue Nov 06, 2012 12:38 pm
by khantisari
Qphoria wrote:Try this...
1. EDIT: catalog/view/theme/default/template/modele/category.tpl
2. FIND:
Code: Select all
<?php if ($category['children']) { ?>
<ul>
3. REPLACE WITH:
Code: Select all
<?php if ($category['children']) { ?>
<ul style="display:block">
this is the simple solution for everyone
thank a lot for this
Re: Subcatagory
Posted: Mon Nov 26, 2012 6:47 pm
by vanderlay359
Hi all,
This is something I want to do on my shop, i.e. list all catagories and sub catagories as default, however I can not find (the below) in the catalog\controller\module\category.php file:
if ($category_id == $result['category_id']) {
$children = $this->getCategories($result['category_id'], $new_path);
}
Please help.
Thanks in advance!
Re: Subcatagory
Posted: Tue Jan 08, 2013 2:41 am
by openinteractive
I am using OC 1.5.2 and have found a pretty simple solution for controlling this.
If you look at the source code in your browser, you will see that the subcategories are in fact being output already, but are hidden with css on line 1093 of the stylesheet.css in this selector:
.box-category > ul > li ul{
display: none;
}
so simply changing display: none; to display:block; will make all subcategories visible like this:
.box-category > ul > li ul{
display: block;
}
and in my case, I only wanted to display one group of category's subcategories, which is easily done by leaving the existing line as is, but creating a second, more specific selector like this:
.box-category > ul > li:nth-of-type(2) ul{
display: block;
}
This will display the subcategories for the second category in your list of categories.but could be easily changed to display any others but changing the "2" value in the pseudo selector nth-of-type(2).
I hope this helps anyone looking for a similar solution.