Post by opencartnoobie2011 » Mon Dec 19, 2011 2:16 am

Hi,

I am having a hard time with this and have searched other posts but they didnt pertain to v1.5.1.3.

Im running v1.5.1.3 and need some menu and sidebar configuration.

When people go to the website and click on the horizontal menu bar, the subcategories will appear on the left-sidebar.

Example:

(Horizontal Sidebar)

CATEGORY ONE
--CATEGORY TWO--CATEGORY THREE--CATEGORY FOUR--CATEGORY FIVE


(LEFT SIDE BAR)
--------------------------
CATEGORY ONE
-Subcategory
-Subcategory
-Subcategory
--------------------------
I only need one category to show when clicked
--------------------------

I will greatly appreciate your help... :D
Last edited by opencartnoobie2011 on Wed Dec 21, 2011 2:00 am, edited 1 time in total.


Posts

Joined
Mon Dec 19, 2011 1:54 am

Post by opencartnoobie2011 » Mon Dec 19, 2011 3:19 am

I really need your help guys...


Posts

Joined
Mon Dec 19, 2011 1:54 am

Post by straightlight » Mon Dec 19, 2011 4:35 am

In catalog/view/theme/<your_template_name>/template/module/category.tpl file,

find this portion:

Code: Select all

<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 } else { ?>
              <a href="<?php echo $child['href']; ?>"> - <?php echo $child['name']; ?></a>
              <?php } ?>
            </li>
            <?php } ?>
          </ul>
replace with:

Code: Select all

<ul>
			<?php $i = 0; ?>
            <?php foreach ($category['children'] as $child) { ?>
            <li>
              <?php if ($child['category_id'] == $child_id && $i == 0) { ?>
              <a href="<?php echo $child['href']; ?>" class="active"> - <?php echo $child['name']; ?></a>
              <?php } elseif ($i == 0) { ?>
              <a href="<?php echo $child['href']; ?>"> - <?php echo $child['name']; ?></a>
              <?php } ?>
            </li>
			<?php $i++; ?>
            <?php } ?>
          </ul>
This should work as expected.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by opencartnoobie2011 » Tue Dec 20, 2011 3:22 am

Hi Straightlight,

Thank you for your work!!

I have changed the coding accordingly but the sidebar did not conform.

I cleaned out my cache and stored settings and checked it on a couple browsers, but the sidebar still remained the same.

Help please :-/
Last edited by opencartnoobie2011 on Tue Dec 20, 2011 3:58 am, edited 1 time in total.


Posts

Joined
Mon Dec 19, 2011 1:54 am

Post by straightlight » Tue Dec 20, 2011 3:36 am

I can't reproduce this with default template. When I click on one category from the sidebar, it only shows the first sub-category as you wanted ...

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by opencartnoobie2011 » Tue Dec 20, 2011 3:58 am

Oh i see...

I am using the default template...that explains why.

Is there anything that we can do pertaining to the default template?


Posts

Joined
Mon Dec 19, 2011 1:54 am

Post by straightlight » Tue Dec 20, 2011 4:00 am

From any templates you imply this code, it should work accordingly.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by opencartnoobie2011 » Tue Dec 20, 2011 5:18 am

I tried it again and it still remained. I have uploaded a screen shot of the categories.

Image

I only need "Body" to be visible.

Example:
Image



Once the user clicks on another category, only that one will be visible as well, but without the other categories visible.

I hope this helps a bit.
I am so sorry If I miss-explained in the beginning.


Posts

Joined
Mon Dec 19, 2011 1:54 am

Post by straightlight » Tue Dec 20, 2011 5:25 am

You could of been clearer stating this was about the counter of the result and not the result itself from the sub-categories.

In catalog/controller/module/category.php file,

find:

Code: Select all

foreach ($categories as $category) {
			$children_data = array();
			
			$children = $this->model_catalog_category->getCategories($category['category_id']);
			
			$i = 0;
			foreach ($children as $child) {
				if ($i == 0) {
					$data = array(
						'filter_category_id'  => $child['category_id'],
						'filter_sub_category' => true
					);		
								
					$children_data[] = array(
						'category_id' => $child['category_id'],
						'name'        => $child['name'],
						'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])						
					);	
				}
				$i++;
			}
			
			$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'])
			);
		}
replace with:

Code: Select all

foreach ($categories as $category) {
			if (((int)$this->data['category_id'] == (int)$category['category_id'])) {
				$children_data = array();
				
				$children = $this->model_catalog_category->getCategories($category['category_id']);
				
				$i = 0;
				foreach ($children as $child) {
					if ($i == 0 && (int)$this->data['category_id'] == (int)$child['category_id']) {
						$data = array(
							'filter_category_id'  => $child['category_id'],
							'filter_sub_category' => true
						);		
									
						$children_data[] = array(
							'category_id' => $child['category_id'],
							'name'        => $child['name'],
							'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])						
						);	
					}
					$i++;
				}
				
				$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,
					'href'        => $this->url->link('product/category', 'path=' . $category['category_id'])
				);
				
				break;
				
			} else {
				$children_data = array();
				
				$children = $this->model_catalog_category->getCategories($category['category_id']);
				
				$i = 0;
				foreach ($children as $child) {					
						$data = array(
							'filter_category_id'  => $child['category_id'],
							'filter_sub_category' => true
						);		
									
						$children_data[] = array(
							'category_id' => $child['category_id'],
							'name'        => $child['name'],
							'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])						
						);	
					
					$i++;
				}
				
				$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,
					'href'        => $this->url->link('product/category', 'path=' . $category['category_id'])
				);
			}
		}
Last edited by straightlight on Tue Dec 20, 2011 8:24 am, edited 4 times in total.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by opencartnoobie2011 » Tue Dec 20, 2011 5:35 am

Hey there,

sorry about that...didnt mean to confuse you.

I am working on v1.5.1.3 of open cart and didnt see the coding you wanted me to find.

Here is my original coding...

Code: Select all

<div class="box">
  <div class="box-heading"><?php echo $heading_title; ?></div>
  <div class="box-content">
    <div class="box-category">
      <ul>
        <?php foreach ($categories as $category) { ?>
        <li>
          <?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 } else { ?>
              <a href="<?php echo $child['href']; ?>"> - <?php echo $child['name']; ?></a>
              <?php } ?>
            </li>
            <?php } ?>
          </ul>
          <?php } ?>
        </li>
        <?php } ?>
      </ul>
    </div>
  </div>
</div>


Posts

Joined
Mon Dec 19, 2011 1:54 am

Post by straightlight » Tue Dec 20, 2011 5:39 am

Compare yours with mine from the location I stated above and it should work just fine. :)

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by opencartnoobie2011 » Tue Dec 20, 2011 5:51 am

Thanks,

I located the Category.tpl file in the module folder but the coding you asked me to find doesn't match with the coding that I have. I have the default Category.tpl file.


Posts

Joined
Mon Dec 19, 2011 1:54 am

Post by straightlight » Tue Dec 20, 2011 5:55 am

The provided code is indeed from the default template of version v1.5.1.3. However, it is from the module as mentioned on the above. Make sure the module is installed from the admin's extension module.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by opencartnoobie2011 » Tue Dec 20, 2011 6:09 am

This is the code from the default Category.tpl File:

I re-downloaded the original opencart just to check if the coding the same. It comes with categories enabled in the admin section.
-------------------------------------------------
/catalog/view/theme/default/template/module/category.tpl
------------------------------------------------
<div class="box">
<div class="box-heading"><?php echo $heading_title; ?></div>
<div class="box-content">
<div class="box-category">
<ul>
<?php foreach ($categories as $category) { ?>
<li>
<?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 } else { ?>
<a href="<?php echo $child['href']; ?>"> - <?php echo $child['name']; ?></a>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
</div>
</div>


Posts

Joined
Mon Dec 19, 2011 1:54 am

Post by straightlight » Tue Dec 20, 2011 6:33 am

Well, yes ... this is no different than my code above ... I don't really understand what should be resolved here ...

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by opencartnoobie2011 » Tue Dec 20, 2011 6:39 am

I cannot find:

Code: Select all

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'])   
            );               
         }
In my coding...

Code: Select all

<div class="box">
<div class="box-heading"><?php echo $heading_title; ?></div>
<div class="box-content">
<div class="box-category">
<ul>
<?php foreach ($categories as $category) { ?>
<li>
<?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 } else { ?>
<a href="<?php echo $child['href']; ?>"> - <?php echo $child['name']; ?></a>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
</div>
</div>


Posts

Joined
Mon Dec 19, 2011 1:54 am

Post by straightlight » Tue Dec 20, 2011 6:46 am

I see. It would seem I didn't had this simple second to edit my topic once I posted it. I changed the tpl extension from extension to php. Sorry for this. That part is in the controller, not template.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by opencartnoobie2011 » Tue Dec 20, 2011 7:14 am

I found:
catalog/controller/module/category.php file and changed the coding accordingly.

It didn't get rid of the other categories

Image

Instead what happened after applying the new code was...

The category "Body (2)" became "Body (1')" in the sidebar along with all of the main categories still intact. Like in figure 1.


Posts

Joined
Mon Dec 19, 2011 1:54 am

Post by straightlight » Tue Dec 20, 2011 7:18 am

If you wish to get rid of the counter entirely from catalog/controller/module/category.php file, after applying these modifications, you can

replace:

Code: Select all

'name'        => $child['name'] . ' (1)',
with this:

Code: Select all

'name'        => $child['name'],
This will simply show the sub-category name without counter.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by opencartnoobie2011 » Tue Dec 20, 2011 7:30 am

Thanks for showing me how to remove the counter.

I only want to show the "body" category when clicked.

The "hair, etc" main categories are still visible. I need them to be gone from the sidebar.

I only want to show one category and its subcategories at a time when clicked on the menu bar.


Posts

Joined
Mon Dec 19, 2011 1:54 am
Who is online

Users browsing this forum: No registered users and 28 guests