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 ?
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 leftcat
>sub cat
>sub sub cat
and i don't think im the only one who would need it
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;
}
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 } ?>
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
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'])
);
}
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>
thanks
I did as you have instructed above, the third level subcat does come out!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 39and 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 5Code: 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']) ); }
hope you get...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>
thanks
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
thx
"We help each other to grow". That's the opencart community!
All free mods
Home Based Ebay business Opportunity(not ads)
Can you be more specific? I am not a coder, so I do not know how should I define "sister_data"...rog3rs wrote:you need to defined the "sister_data" on your controller/module/ file (category.php)marcelwoo wrote: Can you please have it looked into? thx
watch the patterned used by the other variables.
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)
- 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..Parent (7)
-sub-1
----sub 3-1
----sub 3-2
----sub 3-3
-sub-2
----sub 3-1
Thank you
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>
Code: Select all
<?php if ($sisters['category_id'] == $sisters_id) { ?>
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;
}
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'])
);
}
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 } ?>
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;
}
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;
}
8. Now Save, and test the view! :^D !!
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'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>
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
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
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.
I am not sure if it's because I'm using 1.5.1, but there is still an error with this code after movingborrie 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(); } } ?>
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 wrote:I am not sure if it's because I'm using 1.5.1, but there is still an error with this code after movingborrie 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(); } } ?>
beforeCode: Select all
$sister_data = array();
- the originalCode: 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
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!
Users browsing this forum: No registered users and 33 guests