Community Forums

Show Only Subcategories on Sidebar v1.5.1.3 [SOLVED]

General support for technical problems with OpenCart v1.x

Show Only Subcategories on Sidebar v1.5.1.3 [SOLVED]

Postby opencartnoobie2011 » Sun Dec 18, 2011 6:16 pm

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 Tue Dec 20, 2011 6:00 pm, edited 1 time in total.
opencartnoobie2011
 
Posts: 14
Joined: Sun Dec 18, 2011 5:54 pm

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby opencartnoobie2011 » Sun Dec 18, 2011 7:19 pm

I really need your help guys...
opencartnoobie2011
 
Posts: 14
Joined: Sun Dec 18, 2011 5:54 pm

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby straightlight » Sun Dec 18, 2011 8:35 pm

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.
Regards,
Straightlight
straightlight
 
Posts: 1911
Joined: Mon Nov 14, 2011 3:38 pm
Location: Canada, ON

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby opencartnoobie2011 » Mon Dec 19, 2011 7:22 pm

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 Mon Dec 19, 2011 7:58 pm, edited 1 time in total.
opencartnoobie2011
 
Posts: 14
Joined: Sun Dec 18, 2011 5:54 pm

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby straightlight » Mon Dec 19, 2011 7:36 pm

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 ...
Regards,
Straightlight
straightlight
 
Posts: 1911
Joined: Mon Nov 14, 2011 3:38 pm
Location: Canada, ON

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby opencartnoobie2011 » Mon Dec 19, 2011 7:58 pm

Oh i see...

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

Is there anything that we can do pertaining to the default template?
opencartnoobie2011
 
Posts: 14
Joined: Sun Dec 18, 2011 5:54 pm

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby straightlight » Mon Dec 19, 2011 8:00 pm

From any templates you imply this code, it should work accordingly.
Regards,
Straightlight
straightlight
 
Posts: 1911
Joined: Mon Nov 14, 2011 3:38 pm
Location: Canada, ON

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby opencartnoobie2011 » Mon Dec 19, 2011 9:18 pm

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.
opencartnoobie2011
 
Posts: 14
Joined: Sun Dec 18, 2011 5:54 pm

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby straightlight » Mon Dec 19, 2011 9:25 pm

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 12:24 am, edited 4 times in total.
Regards,
Straightlight
straightlight
 
Posts: 1911
Joined: Mon Nov 14, 2011 3:38 pm
Location: Canada, ON

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby opencartnoobie2011 » Mon Dec 19, 2011 9:35 pm

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>
opencartnoobie2011
 
Posts: 14
Joined: Sun Dec 18, 2011 5:54 pm

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby straightlight » Mon Dec 19, 2011 9:39 pm

Compare yours with mine from the location I stated above and it should work just fine. :)
Regards,
Straightlight
straightlight
 
Posts: 1911
Joined: Mon Nov 14, 2011 3:38 pm
Location: Canada, ON

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby opencartnoobie2011 » Mon Dec 19, 2011 9:51 pm

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.
opencartnoobie2011
 
Posts: 14
Joined: Sun Dec 18, 2011 5:54 pm

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby straightlight » Mon Dec 19, 2011 9:55 pm

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.
Regards,
Straightlight
straightlight
 
Posts: 1911
Joined: Mon Nov 14, 2011 3:38 pm
Location: Canada, ON

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby opencartnoobie2011 » Mon Dec 19, 2011 10:09 pm

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>
opencartnoobie2011
 
Posts: 14
Joined: Sun Dec 18, 2011 5:54 pm

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby straightlight » Mon Dec 19, 2011 10:33 pm

Well, yes ... this is no different than my code above ... I don't really understand what should be resolved here ...
Regards,
Straightlight
straightlight
 
Posts: 1911
Joined: Mon Nov 14, 2011 3:38 pm
Location: Canada, ON

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby opencartnoobie2011 » Mon Dec 19, 2011 10:39 pm

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>
opencartnoobie2011
 
Posts: 14
Joined: Sun Dec 18, 2011 5:54 pm

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby straightlight » Mon Dec 19, 2011 10:46 pm

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.
Regards,
Straightlight
straightlight
 
Posts: 1911
Joined: Mon Nov 14, 2011 3:38 pm
Location: Canada, ON

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby opencartnoobie2011 » Mon Dec 19, 2011 11:14 pm

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.
opencartnoobie2011
 
Posts: 14
Joined: Sun Dec 18, 2011 5:54 pm

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby straightlight » Mon Dec 19, 2011 11:18 pm

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.
Regards,
Straightlight
straightlight
 
Posts: 1911
Joined: Mon Nov 14, 2011 3:38 pm
Location: Canada, ON

Re: Show Only Subcategories on Sidebar v1.5.1.3

Postby opencartnoobie2011 » Mon Dec 19, 2011 11:30 pm

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.
opencartnoobie2011
 
Posts: 14
Joined: Sun Dec 18, 2011 5:54 pm

Next

Return to General Support

Who is online

Users browsing this forum: digitalquill, emiku, Google [Bot], mamala, mikeltn, W3C [Validator], Yahoo [Bot] and 92 guests

Hosted by Arvixe Web Hosting