Post by chokoret » Thu Jun 23, 2011 12:20 pm

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 ? :( :'(
Last edited by chokoret on Thu Jul 21, 2011 2:53 am, edited 2 times in total.

User avatar

Posts

Joined
Thu Jun 09, 2011 1:26 am
Location - Los Angeles, CA

Post by chokoret » Sun Jun 26, 2011 12:59 am

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

User avatar

Posts

Joined
Thu Jun 09, 2011 1:26 am
Location - Los Angeles, CA

Post by chokoret » Tue Jun 28, 2011 5:36 am

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 :'(
Last edited by chokoret on Wed Jun 29, 2011 2:10 am, edited 1 time in total.

User avatar

Posts

Joined
Thu Jun 09, 2011 1:26 am
Location - Los Angeles, CA

Post by chokoret » Wed Jun 29, 2011 2:08 am

Really? no one can give me a help? :'(

User avatar

Posts

Joined
Thu Jun 09, 2011 1:26 am
Location - Los Angeles, CA

Post by rog3rs » Fri Jul 01, 2011 1:59 pm

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


Posts

Joined
Wed Jan 12, 2011 9:11 am

Post by rog3rs » Fri Jul 01, 2011 2:26 pm

still working on the header menu part...


Posts

Joined
Wed Jan 12, 2011 9:11 am

Post by marcelwoo » Sun Jul 10, 2011 6:11 pm

rog3rs wrote:Sir,

i was able to solve the issue, actually i was surprise that this is missing on v1.5.0.5, as my version 1.4.9.3 already cater this.

anyways, getting the idea from v.1.4.9.3 below are the code

catalog\controller\modulecategory.php
you must replace your "foreach ($categories as $category) {" line 39

Code: Select all

foreach ($categories as $category) {
		
			$children_data = array();
			
			$children = $this->model_catalog_category->getCategories($category['category_id']);
			
			foreach ($children as $child) {				
				$sister_data = array();
				$sisters = $this->model_catalog_category->getCategories($child['category_id']);
				if(count($sisters) > 1) {
					foreach ($sisters as $sisterMember) {
						$sister_data[] = array(
							'category_id' =>$sisterMember['category_id'],
							'name'        => $sisterMember['name'],
							'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']. '_' . $sisterMember['category_id'])	
						);							
										
					}
					$children_data[] = array(
							'category_id' => $child['category_id'],
							'sister_id'   => $sister_data,
							'name'        => $child['name'],
							'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])	
						);	
				}else{							
					$children_data[] = array(
						'category_id' => $child['category_id'],
						'sister_id' 	=>'',
						'name'        => $child['name'],
						'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])	
					);	
				}
			}			
			$data = array(
				'filter_category_id'  => $category['category_id'],
				'filter_sub_category' => true	
			);		
				
			$product_total = $this->model_catalog_product->getTotalProducts($data);
						
			$this->data['categories'][] = array(
				'category_id' => $category['category_id'],
				'name'        => $category['name'],
				'children'    => $children_data,
				'sister'	 => $sister_data,
				'href'        => $this->url->link('product/category', 'path=' . $category['category_id'])
			);
		}
and on catalog\view\[theme]\template\module\category.php (sorry for the HTML, i need to replace it by PHP as it i need a quick look to understand the loop on code.. again you need to replace your code within the DIV ( <div class="box-category">) from line 5

Code: Select all

<ul>
        <?php foreach ($categories as $category) {
		
		print '<li>';
			if ($category['category_id'] == $category_id) { 
				print '<a href="'.$category['href'].'" class="active">'.$category['name'].'</a>';
			} else { 
				print '<a href="'.$category['href'].'">'.$category['name']."</a>";
			} 
			if ($category['children']) {		
				print '<ul>';
				foreach ($category['children'] as $child) {
					print '<li>';
						if ($child['category_id'] == $child_id) {					
							print '<a href="'.$child['href'].'" class="active"> - '.$child['name']."</a>";							
						} else { 
							print '<a href="'.$child['href'].'"> - '.$child['name'].'</a>';
						}
						if($child['sister_id']){
							print '<ul>';
							foreach($child['sister_id'] as $sisters) {
								print '<li><a href="'.$sisters['href'].'"> - '.$sisters['name'].'</a></li>';
							}
							print '</ul>';
						}
					print '</li>';
				} 
				print '</ul>';
				
			} 
		print '</li>';
        } ?>
      </ul>

hope you get...

thanks
I did as you have instructed above, the third level subcat does come out!
But an error was given on the top of the website header section...... webpages are loaded successfully but the error is there.

Code: Select all

Notice: Undefined variable: sister_data in D:\xampp\htdocs\oc1.5\catalog\controller\module\category.php on line 77
Can you please have it looked into?
thx

"We help each other to grow". That's the opencart community!

All free mods
Home Based Ebay business Opportunity(not ads)


User avatar

Posts

Joined
Tue Mar 29, 2011 1:45 am

Post by rog3rs » Tue Jul 12, 2011 7:23 am

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.


Posts

Joined
Wed Jan 12, 2011 9:11 am

Post by marcelwoo » Tue Jul 12, 2011 10:29 pm

rog3rs wrote:
marcelwoo wrote: Can you please have it looked into? thx
you need to defined the "sister_data" on your controller/module/ file (category.php)
watch the patterned used by the other variables.
Can you be more specific? I am not a coder, so I do not know how should I define "sister_data"...
Where should I "define" it and what codes should I add?

I notice that if any one-level category exists, the error keeps coming out, but if I add a sub-cat to that one-level category, it works just fine.

Thx for your help.

Regards,
Marcel

"We help each other to grow". That's the opencart community!

All free mods
Home Based Ebay business Opportunity(not ads)


User avatar

Posts

Joined
Tue Mar 29, 2011 1:45 am

Post by pakar » Mon Jul 18, 2011 5:47 pm

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


Posts

Joined
Mon Jul 18, 2011 5:35 pm

Post by chokoret » Thu Jul 21, 2011 1:32 am

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

User avatar

Posts

Joined
Thu Jun 09, 2011 1:26 am
Location - Los Angeles, CA

Post by chokoret » Thu Jul 21, 2011 2:52 am

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

User avatar

Posts

Joined
Thu Jun 09, 2011 1:26 am
Location - Los Angeles, CA

Post by borrie » Thu Jul 21, 2011 8:47 pm

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


Posts

Joined
Mon Jan 10, 2011 7:59 pm

Post by borrie » Fri Jul 22, 2011 1:41 am

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>

Last edited by borrie on Fri Jul 22, 2011 3:43 am, edited 2 times in total.


Posts

Joined
Mon Jan 10, 2011 7:59 pm

Post by wend » Thu Aug 04, 2011 1:02 am

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>

Write less, Do more. Learning jQuery, Javascript, PHP, CSS


User avatar

Posts

Joined
Sat Jul 30, 2011 8:56 am
Location - Shenzhen-China

Post by wickedcool » Wed Aug 31, 2011 7:46 pm

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


Posts

Joined
Sat Jul 30, 2011 5:43 pm

Post by kitchenspreston » Fri Sep 02, 2011 8:46 pm

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.


Posts

Joined
Wed Aug 31, 2011 8:54 pm
Location - Lancashire, England

Post by kaylamatthews » Sat Sep 10, 2011 3:49 am

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


Posts

Joined
Wed Jun 01, 2011 12:30 pm

Post by az-vm » Mon Oct 03, 2011 7:19 am

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


Posts

Joined
Sat Jul 30, 2011 7:53 am
Location - Men at Work @ It´s a Mistake

Post by romeo2k » Thu Nov 17, 2011 5:52 am

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!


Posts

Joined
Wed Nov 16, 2011 8:57 pm
Who is online

Users browsing this forum: No registered users and 8 guests