Page 1 of 4

[SOLVED][1.5] one more level of sub category!

Posted: Thu Jun 23, 2011 12:20 pm
by chokoret
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 ? :( :'(

Re: [1.5] Just one more level of sub category please :(

Posted: Sun Jun 26, 2011 12:59 am
by chokoret
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
cat
>sub cat
>sub sub cat
format on the left

and i don't think im the only one who would need it :(

Re: [1.5] Just one more level of sub category please :(

Posted: Tue Jun 28, 2011 5:36 am
by chokoret
not giving up a hope yet :'(

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 :'(

Re: [1.5] Just one more level of sub category please :(

Posted: Wed Jun 29, 2011 2:08 am
by chokoret
Really? no one can give me a help? :'(

Re: [1.5] Just one more level of sub category please :(

Posted: Fri Jul 01, 2011 1:59 pm
by rog3rs
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

Re: [1.5] Just one more level of sub category please :(

Posted: Fri Jul 01, 2011 2:26 pm
by rog3rs
still working on the header menu part...

Re: [1.5] Just one more level of sub category please :(

Posted: Sun Jul 10, 2011 6:11 pm
by marcelwoo
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

Re: [1.5] Just one more level of sub category please :(

Posted: Tue Jul 12, 2011 7:23 am
by rog3rs
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.

Re: [1.5] Just one more level of sub category please :(

Posted: Tue Jul 12, 2011 10:29 pm
by marcelwoo
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

Re: [1.5] Just one more level of sub category please :(

Posted: Mon Jul 18, 2011 5:47 pm
by pakar
Can anybody help me please, how to make categories looks like :
- 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

Re: [1.5] Just one more level of sub category please :(

Posted: Thu Jul 21, 2011 1:32 am
by chokoret
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

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...

Re: [1.5] Just one more level of sub category please :(

Posted: Thu Jul 21, 2011 2:52 am
by chokoret
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

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 !!

Re: [SOLVED][1.5] one more level of sub category!

Posted: Thu Jul 21, 2011 8:47 pm
by borrie
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();
  	}
}
?>

Re: [SOLVED][1.5] one more level of sub category!

Posted: Fri Jul 22, 2011 1:41 am
by borrie
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:

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>


Re: [SOLVED][1.5] one more level of sub category!

Posted: Thu Aug 04, 2011 1:02 am
by wend
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

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>

Re: [SOLVED][1.5] one more level of sub category!

Posted: Wed Aug 31, 2011 7:46 pm
by wickedcool
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

Re: [SOLVED][1.5] one more level of sub category!

Posted: Fri Sep 02, 2011 8:46 pm
by kitchenspreston
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.

Re: [SOLVED][1.5] one more level of sub category!

Posted: Sat Sep 10, 2011 3:49 am
by kaylamatthews
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();
before

Code: Select all

foreach ($children as $child) {
- the original

Code: Select all

$sister_data = array();
must also remain in the same place for the code to work, otherwise some categories will display other categories' sub-categories!

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();
  	}
}
?>

Re: [SOLVED][1.5] one more level of sub category!

Posted: Mon Oct 03, 2011 7:19 am
by az-vm
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 moving

Code: Select all

$sister_data = array();
before

Code: Select all

foreach ($children as $child) {
- the original

Code: Select all

$sister_data = array();
must also remain in the same place for the code to work, otherwise some categories will display other categories' sub-categories!

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

Re: [SOLVED][1.5] one more level of sub category!

Posted: Thu Nov 17, 2011 5:52 am
by romeo2k
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 ? :D

Thank you!