[SOLVED][1.5] one more level of sub category!
57 posts
• Page 1 of 3 • 1, 2, 3
[SOLVED][1.5] one more level of sub category!
Im editing template for 1.5x open cart, and found out that the Menu one the left hand side - shows only upto second sub category..
and i'v been looking up controller files, template files, to edit it as I want - show just one more level (or all levels..as long as I can get more deeper level of sub sub cats..) of sub categories on the navigation on the left --- for couple weeks..and could not find the way...
can anyone help this out please ?

and i'v been looking up controller files, template files, to edit it as I want - show just one more level (or all levels..as long as I can get more deeper level of sub sub cats..) of sub categories on the navigation on the left --- for couple weeks..and could not find the way...
can anyone help this out please ?

Last edited by chokoret on Wed Jul 20, 2011 6:53 pm, edited 2 times in total.
-

chokoret - Posts: 47
- Joined: Wed Jun 08, 2011 5:26 pm
- Location: Los Angeles, CA
Re: [1.5] Just one more level of sub category please :(
anyone can help?
I'v been searching all forums with no luck
all threads I found those are related to category were all for 1.4 version..
just want
format on the left
and i don't think im the only one who would need it
I'v been searching all forums with no luck

all threads I found those are related to category were all for 1.4 version..

just want
cat
>sub cat
>sub sub cat
format on the left
and i don't think im the only one who would need it

-

chokoret - Posts: 47
- Joined: Wed Jun 08, 2011 5:26 pm
- Location: Los Angeles, CA
Re: [1.5] Just one more level of sub category please :(
not giving up a hope yet 
I guess i'm making a progress..
for catalog/controller/module/category.php I added
Under
and also added
under
And for template/module/category.tpl
I added
under
For the result, I was able to call out the sub-sub category name and id under sub category.
But this has serious problem, it only calls out the sub-sub for the last sub category - for all sub cats..
so it shows like this now.....
Parent
-sub 1
----sub 3-1
----sub 3-2
----sub 3-3
-sub 2
----sub 3-1
----sub 3-2
----sub 3-3
-sub 3
----sub 3-1
----sub 3-2
----sub 3-3
(of course sub-sub list shows only when the child was active)
Can anyone help to find the solution out? im keep working to find one but heard it should be very easy issue with those who knows php and unfortunately i'm not really a programmer

I guess i'm making a progress..
for catalog/controller/module/category.php I added
- Code: Select all
if (isset($parts[2])) {
$this->data['sister_id'] = $parts[2];
} else {
$this->data['sister_id'] = 0;
}
Under
- Code: Select all
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;
}
and also added
- Code: Select all
$sisters_data = array();
$sisters = $this->model_catalog_category->getCategories($child['category_id']);
foreach ($sisters as $sister) {
$data = array(
'filter_category_id' => $sister['category_id'],
'filter_sub_category' => true
);
$sisters_data[] = array(
'category_id' => $sister['category_id'],
'name' => $sister['name'],
'href' => $this->url->link('product/category', 'path=' .
$category['category_id'] . '_' . $child['category_id'] . '_' . $sister['category_id'])
);
}
under
- Code: Select all
foreach ($children as $child) {
And for template/module/category.tpl
I added
- Code: Select all
<?php if ($category['sisters']) { ?>
<ul>
<?php foreach ($category['sisters'] as $sister) { ?>
<li>
<?php if ($sister['category_id'] == $sister_id) { ?>
<a href="<?php echo $sister['href']; ?>" class="active"> <?php echo $sister['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $sister['href']; ?>"> <?php echo $sister['name']; ?></a>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
under
- Code: Select all
<?php if ($child['category_id'] == $child_id) { ?>
<a href="<?php echo $child['href']; ?>" class="active"> <?php echo $child['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $child['href']; ?>"> <?php echo $child['name']; ?></a>
<?php } ?>
For the result, I was able to call out the sub-sub category name and id under sub category.
But this has serious problem, it only calls out the sub-sub for the last sub category - for all sub cats..
so it shows like this now.....
Parent
-sub 1
----sub 3-1
----sub 3-2
----sub 3-3
-sub 2
----sub 3-1
----sub 3-2
----sub 3-3
-sub 3
----sub 3-1
----sub 3-2
----sub 3-3
(of course sub-sub list shows only when the child was active)
Can anyone help to find the solution out? im keep working to find one but heard it should be very easy issue with those who knows php and unfortunately i'm not really a programmer

Last edited by chokoret on Tue Jun 28, 2011 6:10 pm, edited 1 time in total.
-

chokoret - Posts: 47
- Joined: Wed Jun 08, 2011 5:26 pm
- Location: Los Angeles, CA
Re: [1.5] Just one more level of sub category please :(
Really? no one can give me a help? 

-

chokoret - Posts: 47
- Joined: Wed Jun 08, 2011 5:26 pm
- Location: Los Angeles, CA
Re: [1.5] Just one more level of sub category please :(
Sir,
i was able to solve the issue, actually i was surprise that this is missing on v1.5.0.5, as my version 1.4.9.3 already cater this.
anyways, getting the idea from v.1.4.9.3 below are the code
catalog\controller\modulecategory.php
you must replace your "foreach ($categories as $category) {" line 39
and on catalog\view\[theme]\template\module\category.php (sorry for the HTML, i need to replace it by PHP as it i need a quick look to understand the loop on code.. again you need to replace your code within the DIV ( <div class="box-category">) from line 5
hope you get...
thanks
i was able to solve the issue, actually i was surprise that this is missing on v1.5.0.5, as my version 1.4.9.3 already cater this.
anyways, getting the idea from v.1.4.9.3 below are the code
catalog\controller\modulecategory.php
you must replace your "foreach ($categories as $category) {" line 39
- Code: Select all
foreach ($categories as $category) {
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$sister_data = array();
$sisters = $this->model_catalog_category->getCategories($child['category_id']);
if(count($sisters) > 1) {
foreach ($sisters as $sisterMember) {
$sister_data[] = array(
'category_id' =>$sisterMember['category_id'],
'name' => $sisterMember['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']. '_' . $sisterMember['category_id'])
);
}
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' => $sister_data,
'name' => $child['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}else{
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' =>'',
'name' => $child['name'],
'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'],
'children' => $children_data,
'sister' => $sister_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
and on catalog\view\[theme]\template\module\category.php (sorry for the HTML, i need to replace it by PHP as it i need a quick look to understand the loop on code.. again you need to replace your code within the DIV ( <div class="box-category">) from line 5
- Code: Select all
<ul>
<?php foreach ($categories as $category) {
print '<li>';
if ($category['category_id'] == $category_id) {
print '<a href="'.$category['href'].'" class="active">'.$category['name'].'</a>';
} else {
print '<a href="'.$category['href'].'">'.$category['name']."</a>";
}
if ($category['children']) {
print '<ul>';
foreach ($category['children'] as $child) {
print '<li>';
if ($child['category_id'] == $child_id) {
print '<a href="'.$child['href'].'" class="active"> - '.$child['name']."</a>";
} else {
print '<a href="'.$child['href'].'"> - '.$child['name'].'</a>';
}
if($child['sister_id']){
print '<ul>';
foreach($child['sister_id'] as $sisters) {
print '<li><a href="'.$sisters['href'].'"> - '.$sisters['name'].'</a></li>';
}
print '</ul>';
}
print '</li>';
}
print '</ul>';
}
print '</li>';
} ?>
</ul>
hope you get...
thanks
- rog3rs
- Posts: 3
- Joined: Wed Jan 12, 2011 1:11 am
Re: [1.5] Just one more level of sub category please :(
still working on the header menu part...
- rog3rs
- Posts: 3
- Joined: Wed Jan 12, 2011 1:11 am
Re: [1.5] Just one more level of sub category please :(
rog3rs wrote:Sir,
i was able to solve the issue, actually i was surprise that this is missing on v1.5.0.5, as my version 1.4.9.3 already cater this.
anyways, getting the idea from v.1.4.9.3 below are the code
catalog\controller\modulecategory.php
you must replace your "foreach ($categories as $category) {" line 39
- Code: Select all
foreach ($categories as $category) {
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$sister_data = array();
$sisters = $this->model_catalog_category->getCategories($child['category_id']);
if(count($sisters) > 1) {
foreach ($sisters as $sisterMember) {
$sister_data[] = array(
'category_id' =>$sisterMember['category_id'],
'name' => $sisterMember['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']. '_' . $sisterMember['category_id'])
);
}
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' => $sister_data,
'name' => $child['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}else{
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' =>'',
'name' => $child['name'],
'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'],
'children' => $children_data,
'sister' => $sister_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
and on catalog\view\[theme]\template\module\category.php (sorry for the HTML, i need to replace it by PHP as it i need a quick look to understand the loop on code.. again you need to replace your code within the DIV ( <div class="box-category">) from line 5
- Code: Select all
<ul>
<?php foreach ($categories as $category) {
print '<li>';
if ($category['category_id'] == $category_id) {
print '<a href="'.$category['href'].'" class="active">'.$category['name'].'</a>';
} else {
print '<a href="'.$category['href'].'">'.$category['name']."</a>";
}
if ($category['children']) {
print '<ul>';
foreach ($category['children'] as $child) {
print '<li>';
if ($child['category_id'] == $child_id) {
print '<a href="'.$child['href'].'" class="active"> - '.$child['name']."</a>";
} else {
print '<a href="'.$child['href'].'"> - '.$child['name'].'</a>';
}
if($child['sister_id']){
print '<ul>';
foreach($child['sister_id'] as $sisters) {
print '<li><a href="'.$sisters['href'].'"> - '.$sisters['name'].'</a></li>';
}
print '</ul>';
}
print '</li>';
}
print '</ul>';
}
print '</li>';
} ?>
</ul>
hope you get...
thanks
I did as you have instructed above, the third level subcat does come out!
But an error was given on the top of the website header section...... webpages are loaded successfully but the error is there.
- Code: Select all
Notice: Undefined variable: sister_data in D:\xampp\htdocs\oc1.5\catalog\controller\module\category.php on line 77
Can you please have it looked into?
thx
"We help each other to grow". That's the opencart community!
All free mods
Home Based Ebay business Opportunity(not ads)
All free mods
Home Based Ebay business Opportunity(not ads)
-

marcelwoo - Posts: 291
- Joined: Mon Mar 28, 2011 5:45 pm
Re: [1.5] Just one more level of sub category please :(
marcelwoo wrote:Can you please have it looked into? thx
you need to defined the "sister_data" on your controller/module/ file (category.php)
watch the patterned used by the other variables.
- rog3rs
- Posts: 3
- Joined: Wed Jan 12, 2011 1:11 am
Re: [1.5] Just one more level of sub category please :(
rog3rs wrote:marcelwoo wrote:Can you please have it looked into? thx
you need to defined the "sister_data" on your controller/module/ file (category.php)
watch the patterned used by the other variables.
Can you be more specific? I am not a coder, so I do not know how should I define "sister_data"...
Where should I "define" it and what codes should I add?
I notice that if any one-level category exists, the error keeps coming out, but if I add a sub-cat to that one-level category, it works just fine.
Thx for your help.
Regards,
Marcel
"We help each other to grow". That's the opencart community!
All free mods
Home Based Ebay business Opportunity(not ads)
All free mods
Home Based Ebay business Opportunity(not ads)
-

marcelwoo - Posts: 291
- Joined: Mon Mar 28, 2011 5:45 pm
Re: [1.5] Just one more level of sub category please :(
Can anybody help me please, how to make categories looks like :
- parent, show counter of sub categories
- sub-categories, not show
maybe like :
And, how to make sub 3-1 level linked directly to the product/ page? -- no need again to categories, directly to show the product..
Thank you
- parent, show counter of sub categories
- sub-categories, not show
maybe like :
Parent (7)
-sub-1
----sub 3-1
----sub 3-2
----sub 3-3
-sub-2
----sub 3-1
And, how to make sub 3-1 level linked directly to the product/ page? -- no need again to categories, directly to show the product..
Thank you
- pakar
- Posts: 1
- Joined: Mon Jul 18, 2011 9:35 am
Re: [1.5] Just one more level of sub category please :(
thank you thank you Roger!!! It worked!!!!!!!!
But may I ask one more thing?? I want this "sister" link to be bold and colored when is selected like other upper categories..
I already coded CSS for it, but still struggling on tpl file to make it work,
What i have tried was
but doesn't work...I think I need to do something on
this part, can not fide the way to activate "active" class for this link...
But may I ask one more thing?? I want this "sister" link to be bold and colored when is selected like other upper categories..
I already coded CSS for it, but still struggling on tpl file to make it work,
What i have tried was
- Code: Select all
<li>
<?php if ($sisters['category_id'] == $sisters_id) { ?>
<a href="<?php echo $sisters['href']; ?>" class="active"> <?php echo $sisters['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $sisters['href']; ?>"> <?php echo $sisters['name']; ?></a>
<?php } ?>
</li>
but doesn't work...I think I need to do something on
- Code: Select all
<?php if ($sisters['category_id'] == $sisters_id) { ?>
this part, can not fide the way to activate "active" class for this link...
-

chokoret - Posts: 47
- Joined: Wed Jun 08, 2011 5:26 pm
- Location: Los Angeles, CA
Re: [1.5] Just one more level of sub category please :(
FIGURED OUT!!!!!! LET ME CLEAN THIS UP FOR THOSE WHO NEED THIS!! :^D
THANKX A MILLION ROGER!!
1. Open catalog/controller/module/category.php to edit , and find this part
2. and after , ADD this
3. Find this part
(this is below $categories = $this->model_catalog_category->getCategories(0);
and above if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/category.tpl')) { )
4. and REPLACE that with this ::
5. Now save. and open cataloge/view/theme/*yourtheme*/template/module/category.tpl , FIND
6. and under that, ADD
7. Now save, and go open catalog/view/theme/*yourtheme/stylesheet/stylesheet.css
FIND
8. and under that, ADD
( #06bcc3 is color code, you might want to change it to the color you want)
8. Now Save, and test the view! :^D !!
THANKX A MILLION ROGER!!
1. Open catalog/controller/module/category.php to edit , and find this part
- Code: Select all
if (isset($parts[1])) {
$this->data['child_id'] = $parts[1];
} else {
$this->data['child_id'] = 0;
}
2. and after , ADD this
- Code: Select all
if (isset($parts[2])) {
$this->data['sisters_id'] = $parts[2];
} else {
$this->data['sisters_id'] = 0;
}
3. Find this part
- Code: Select all
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'])
);
}
(this is below $categories = $this->model_catalog_category->getCategories(0);
and above if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/category.tpl')) { )
4. and REPLACE that with this ::
- Code: Select all
foreach ($categories as $category) {
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$sister_data = array();
$sisters = $this->model_catalog_category->getCategories($child['category_id']);
if(count($sisters) > 1) {
foreach ($sisters as $sisterMember) {
$sister_data[] = array(
'category_id' =>$sisterMember['category_id'],
'name' => $sisterMember['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']. '_' . $sisterMember['category_id'])
);
}
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' => $sister_data,
'name' => $child['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}else{
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' =>'',
'name' => $child['name'],
'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'],
'children' => $children_data,
'sister' => $sister_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
5. Now save. and open cataloge/view/theme/*yourtheme*/template/module/category.tpl , FIND
- Code: Select all
<?php foreach ($category['children'] as $child) { ?>
<li>
<?php if ($child['category_id'] == $child_id) { ?>
<a href="<?php echo $child['href']; ?>" class="active"> - <?php echo $child['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $child['href']; ?>"> - <?php echo $child['name']; ?></a>
<?php } ?>
6. and under that, ADD
- Code: Select all
<?php if($child['sister_id']){ ?>
<ul>
<?php foreach($child['sister_id'] as $sisters) { ?>
<li>
<?php if ($sisters['category_id'] == $sisters_id) { ?>
<a href="<?php echo $sisters['href']; ?>" class="active"> - <?php echo $sisters['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $sisters['href']; ?>"> - <?php echo $sisters['name']; ?></a>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
7. Now save, and go open catalog/view/theme/*yourtheme/stylesheet/stylesheet.css
FIND
- Code: Select all
.box-category > ul > li ul > li > a.active + ul {
display: block;
}
8. and under that, ADD
- Code: Select all
.box-category > ul > li ul > li ul > li a.active {
font-weight: bold;
color: #06bcc3;
}
.box-category > ul > li ul > li ul > li a.active + ul {
display: block;
}
( #06bcc3 is color code, you might want to change it to the color you want)
8. Now Save, and test the view! :^D !!
-

chokoret - Posts: 47
- Joined: Wed Jun 08, 2011 5:26 pm
- Location: Los Angeles, CA
Re: [SOLVED][1.5] one more level of sub category!
move "$sister_data = array();" above "foreach ($children as $child) { "
else you will get an error in the top of your page.
Complete code of controller/module/category.php
else you will get an error in the top of your page.
Complete code of controller/module/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;
}
/* add for level 3 subs category's */
if (isset($parts[2])) {
$this->data['sisters_id'] = $parts[2];
} else {
$this->data['sisters_id'] = 0;
}
/* end add */
$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'])
);
}*/
/* start replaced code for subcategory's */
foreach ($categories as $category) {
$children_data = array();
$sister_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$sisters = $this->model_catalog_category->getCategories($child['category_id']);
if(count($sisters) > 1) {
foreach ($sisters as $sisterMember) {
$sister_data[] = array(
'category_id' => $sisterMember['category_id'],
'name' => $sisterMember['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']. '_' . $sisterMember['category_id'])
);
}
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' => $sister_data,
'name' => $child['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}else{
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' => '',
'name' => $child['name'],
'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'],
'children' => $children_data,
'sister' => $sister_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
/* end */
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();
}
}
?>
- borrie
- Posts: 49
- Joined: Mon Jan 10, 2011 11:59 am
Re: [SOLVED][1.5] one more level of sub category!
Could some one help me out?
i've modified the script so it will show level 3 & level 4 in the categories.
results
Cat A
Cat A > SubCat A>
Cat A > SubCat A> Subcat AA
Cat A > SubCat A> Subcat AA > Subcat 1
Cat A > SubCat A> Subcat AA > Subcat 2
Cat A
Cat A > SubCat A>
Cat A > SubCat A> Subcat BB
Cat A > SubCat A> Subcat BB > Subcat 3
Cat A > SubCat A> Subcat BB > Subcat 4
but Subcat 1 links to subcat 3, and subcat 2 links to subcat 4
Subcar 3+4 are linking correctly.
MY CODE:
template code
i've modified the script so it will show level 3 & level 4 in the categories.
results
Cat A
Cat A > SubCat A>
Cat A > SubCat A> Subcat AA
Cat A > SubCat A> Subcat AA > Subcat 1
Cat A > SubCat A> Subcat AA > Subcat 2
Cat A
Cat A > SubCat A>
Cat A > SubCat A> Subcat BB
Cat A > SubCat A> Subcat BB > Subcat 3
Cat A > SubCat A> Subcat BB > Subcat 4
but Subcat 1 links to subcat 3, and subcat 2 links to subcat 4
Subcar 3+4 are linking correctly.
MY CODE:
- 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;
}
/* add for level 3 subs category's */
if (isset($parts[2])) {
$this->data['sisters_id'] = $parts[2];
} else {
$this->data['sisters_id'] = 0;
}
/* end add */
/* add for level 4 subs category's */
if (isset($parts[3])) {
$this->data['brothers_id'] = $parts[3];
} else {
$this->data['brothers_id'] = 0;
}
/* end add */
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$this->data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
/* start replaced code for subcategory's */
foreach ($categories as $category) {
$children_data = array();
$sister_data = array();
$brother_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$sisters = $this->model_catalog_category->getCategories($child['category_id']);
if(count($sisters) > 1 ) {
foreach ($sisters as $sisterMember) {
$sister_data[] = array(
'category_id' => $sisterMember['category_id'],
'name' => $sisterMember['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']. '_' . $sisterMember['category_id'])
);
}
$brothers = $this->model_catalog_category->getCategories($sisterMember['category_id']);
if(count($brothers) > 1) {
foreach ($brothers as $brotherMember) {
$brother_data[] = array(
'category_id' => $brotherMember['category_id'],
'name' => $brotherMember['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']. '_' . $sisterMember['category_id'] . '_' . $brotherMember['category_id'])
);
}
}
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' => $sister_data,
'brother_id' => $brother_data,
'name' => $child['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}else{
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' => '',
'brother_id' => '',
'name' => $child['name'],
'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'],
'children' => $children_data,
'sister' => $sister_data,
'brother' => $brother_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
/* end */
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();
}
}
?>
template code
- Code: Select all
<div class="box">
<div class="box-heading"><span class="category"><?php echo $heading_title; ?></span></div>
<div class="box-content">
<div class="box-category">
<ul>
<?php foreach ($categories as $category) { ?>
<li class="">
<?php if ($category['category_id'] == $category_id) { ?>
<a href="<?php echo $category['href']; ?>" class="active"><?php echo $category['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php } ?>
<?php if ($category['children']) { ?>
<ul>
<?php foreach ($category['children'] as $child) { ?>
<li>
<?php if ($child['category_id'] == $child_id) { ?>
<a href="<?php echo $child['href']; ?>" class="active"> - <?php echo $child['name']; ?></a>
<?php if($child['sister_id']){ ?>
<ul>
<?php foreach($child['sister_id'] as $sisters) { ?>
<li>
<?php if ($sisters['category_id'] == $sisters_id) { ?>
<a href="<?php echo $sisters['href']; ?>" class="active"> - <?php echo $sisters['name']; ?></a>
<?php if($child['brother_id']){ ?>
<ul>
<?php foreach($child['brother_id'] as $brothers) { ?>
<li>
<?php if ($brothers['category_id'] == $brothers_id) { ?>
<a href="<?php echo $brothers['href']; ?>" class="active"> - <?php echo $brothers['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $brothers['href']; ?>"> - <?php echo $brothers['name']; ?></a>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
<?php } else { ?>
<a href="<?php echo $sisters['href']; ?>"> - <?php echo $sisters['name']; ?></a>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
<?php } else { ?>
<a href="<?php echo $child['href']; ?>"> - <?php echo $child['name']; ?></a>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
</div>
</div>
Last edited by borrie on Thu Jul 21, 2011 7:43 pm, edited 2 times in total.
- borrie
- Posts: 49
- Joined: Mon Jan 10, 2011 11:59 am
Re: [SOLVED][1.5] one more level of sub category!
I may write some jquery code, Change the css style of sub-categories.
Add these code to the end of Your_Template/template/header.tpl
Add these code to the end of Your_Template/template/header.tpl
- Code: Select all
<script type="text/javascript">
$(document).ready(function(){
$('.box-category ul li ul').css("display","block");
//$('.box-category ul li ul li ul').css("display","block"); //this may display sub sub categories.
});
</script>
Write less, Do more. Learning jQuery, Javascript, PHP, CSS
-

wend - Posts: 8
- Joined: Sat Jul 30, 2011 12:56 am
- Location: Shenzhen-China
Re: [SOLVED][1.5] one more level of sub category!
Sorry to revise an old thread - but does anyone have a clue on what changes to make in the header.tpl and stylesheet.css in order to show the sisters (cat->sub->sub) in the header dropdown menu?
I can probably work out some of the php in header.tpl myself, given enough time, but the stylesheet.css changes will likely throw me off.
Has anyone done this yet?
Thanks
I can probably work out some of the php in header.tpl myself, given enough time, but the stylesheet.css changes will likely throw me off.
Has anyone done this yet?
Thanks
- wickedcool
- Posts: 7
- Joined: Sat Jul 30, 2011 9:43 am
Re: [SOLVED][1.5] one more level of sub category!
Hi
Am new to opencart and have tried the above regarding adding an additional sub category to the menu. I get to step 7 and the code is not present in the default template. I have managed all the other stages but as I am not php coder I have no idea how to proceed.
To conclude I need to add a sub menu to an existing sub menu for the default template.
Am new to opencart and have tried the above regarding adding an additional sub category to the menu. I get to step 7 and the code is not present in the default template. I have managed all the other stages but as I am not php coder I have no idea how to proceed.
To conclude I need to add a sub menu to an existing sub menu for the default template.
- kitchenspreston
- Posts: 3
- Joined: Wed Aug 31, 2011 12:54 pm
- Location: Lancashire, England
Re: [SOLVED][1.5] one more level of sub category!
borrie wrote:move "$sister_data = array();" above "foreach ($children as $child) { "
else you will get an error in the top of your page.
Complete code of controller/module/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;
}
/* add for level 3 subs category's */
if (isset($parts[2])) {
$this->data['sisters_id'] = $parts[2];
} else {
$this->data['sisters_id'] = 0;
}
/* end add */
$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'])
);
}*/
/* start replaced code for subcategory's */
foreach ($categories as $category) {
$children_data = array();
$sister_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$sisters = $this->model_catalog_category->getCategories($child['category_id']);
if(count($sisters) > 1) {
foreach ($sisters as $sisterMember) {
$sister_data[] = array(
'category_id' => $sisterMember['category_id'],
'name' => $sisterMember['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']. '_' . $sisterMember['category_id'])
);
}
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' => $sister_data,
'name' => $child['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}else{
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' => '',
'name' => $child['name'],
'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'],
'children' => $children_data,
'sister' => $sister_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
/* end */
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 am not sure if it's because I'm using 1.5.1, but there is still an error with this code after moving
- Code: Select all
$sister_data = array();
- Code: Select all
foreach ($children as $child) {
- Code: Select all
$sister_data = array();
Also, only categories with more than one sub-categories is displaying any sub-categories, so I have made some modification to display all sub-categories (even categories with just one sub-category) now.
Here is the complete /module/category.php file, it works in my 1.5.1 and should work perfectly in 1.5.0.x as well
- 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;
}
if (isset($parts[2])) {
$this->data['sisters_id'] = $parts[2];
} else {
$this->data['sisters_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();
$sister_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$sister_data = array();
$sisters = $this->model_catalog_category->getCategories($child['category_id']);
if($sisters) {
foreach ($sisters as $sisterMember) {
$sister_data[] = array(
'category_id' =>$sisterMember['category_id'],
'name' => $sisterMember['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']. '_' . $sisterMember['category_id'])
);
}
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' => $sister_data,
'name' => $child['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}else{
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' =>'',
'name' => $child['name'],
'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'],
'children' => $children_data,
'sister' => $sister_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();
}
}
?>
- kaylamatthews
- Posts: 36
- Joined: Wed Jun 01, 2011 4:30 am
Re: [SOLVED][1.5] one more level of sub category!
kaylamatthews wrote:borrie wrote:move "$sister_data = array();" above "foreach ($children as $child) { "
else you will get an error in the top of your page.
Complete code of controller/module/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;
}
/* add for level 3 subs category's */
if (isset($parts[2])) {
$this->data['sisters_id'] = $parts[2];
} else {
$this->data['sisters_id'] = 0;
}
/* end add */
$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'])
);
}*/
/* start replaced code for subcategory's */
foreach ($categories as $category) {
$children_data = array();
$sister_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$sisters = $this->model_catalog_category->getCategories($child['category_id']);
if(count($sisters) > 1) {
foreach ($sisters as $sisterMember) {
$sister_data[] = array(
'category_id' => $sisterMember['category_id'],
'name' => $sisterMember['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']. '_' . $sisterMember['category_id'])
);
}
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' => $sister_data,
'name' => $child['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}else{
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' => '',
'name' => $child['name'],
'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'],
'children' => $children_data,
'sister' => $sister_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
/* end */
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 am not sure if it's because I'm using 1.5.1, but there is still an error with this code after movingbefore
- Code: Select all
$sister_data = array();- the original
- Code: Select all
foreach ($children as $child) {must also remain in the same place for the code to work, otherwise some categories will display other categories' sub-categories!
- Code: Select all
$sister_data = array();
Also, only categories with more than one sub-categories is displaying any sub-categories, so I have made some modification to display all sub-categories (even categories with just one sub-category) now.
Here is the complete /module/category.php file, it works in my 1.5.1 and should work perfectly in 1.5.0.x as well
- 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;
}
if (isset($parts[2])) {
$this->data['sisters_id'] = $parts[2];
} else {
$this->data['sisters_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();
$sister_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$sister_data = array();
$sisters = $this->model_catalog_category->getCategories($child['category_id']);
if($sisters) {
foreach ($sisters as $sisterMember) {
$sister_data[] = array(
'category_id' =>$sisterMember['category_id'],
'name' => $sisterMember['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']. '_' . $sisterMember['category_id'])
);
}
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' => $sister_data,
'name' => $child['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}else{
$children_data[] = array(
'category_id' => $child['category_id'],
'sister_id' =>'',
'name' => $child['name'],
'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'],
'children' => $children_data,
'sister' => $sister_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();
}
}
?>
Hi there,
is this working to you on OC 1.5.1 ?
can you past the code you use on the category.tpl and the css modifications?
Thank´s
Az-Vm
- az-vm
- Posts: 37
- Joined: Fri Jul 29, 2011 11:53 pm
- Location: Men at Work @ It´s a Mistake
Re: [SOLVED][1.5] one more level of sub category!
Heloo all
i stil cant get to display
maincat
- subcat1
- - subsubcat1
- - - subsubsubcat1
my page http://www.najceneje.eu/index.php?route ... h=20_26_63
please someone help me ?
Thank you!
i stil cant get to display
maincat
- subcat1
- - subsubcat1
- - - subsubsubcat1
my page http://www.najceneje.eu/index.php?route ... h=20_26_63
please someone help me ?

Thank you!
- romeo2k
- Posts: 8
- Joined: Wed Nov 16, 2011 12:57 pm
57 posts
• Page 1 of 3 • 1, 2, 3
Who is online
Users browsing this forum: davidmarch, eurekasprings and 20 guests













