Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How to hide categories with no products


brounea

Recommended Posts

Hi,

 

As you can see, I'm new to this community.

 

I have a basic question (maybe this was asked before) but it goes like this:

 

On my shop there are lots and lots of categories & subCategories.

The items in categories may or may not exsist depending on avaiability or the category is just a "place holder" for its sub-categories.

 

My questions :

 

1) Is there a way to hide the "empty" categories" - categories with no products?

2) I do not want to just delete them.

3) What query do i need to run to get this effect?

4) Where should I plug this query?

 

Thanks for any help

 

--Brounea

Link to comment
Share on other sites

Check the contributions, there is one that will allow you to hide unused categories

The Knowledge Base is a wonderful thing.

Do you have a problem? Have you checked out Common Problems?

There are many very useful osC Contributions

Are you having trouble with a installed contribution? Have you checked out the support thread found Here

BACKUP BACKUP BACKUP!!! You did backup, right??

Link to comment
Share on other sites

ozcsys,

 

    I looked there for a while and could not find anything that has that feature.

   

    Do you remember the name of it?

 

Thanks

 

No but I did a search for categories and found it on the second page

 

HERE

The Knowledge Base is a wonderful thing.

Do you have a problem? Have you checked out Common Problems?

There are many very useful osC Contributions

Are you having trouble with a installed contribution? Have you checked out the support thread found Here

BACKUP BACKUP BACKUP!!! You did backup, right??

Link to comment
Share on other sites

Save this as includes/boxes/categories.php

 

This is automatic -if a parent or sub category is empty, it will not show in the box.

You also have the option of expanded or collapsed sub-categories (look towards the end of the file for this).

 

<?php
/*
 $Id: categories.php,v 1.17 2002/03/07 20:53:58 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2001 osCommerce

 Released under the GNU General Public License
*/

// Categories_tree written by Gideon Romm from Symbio Technologies, LLC

function tep_show_category($cid, $cpath, $COLLAPSABLE) {
 global $categories_string, $languages_id, $HTTP_GET_VARS;
 global $level;
 $selectedPath = array();
 
// Get all of the categories on this level

 $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . 

TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = " . $cid . " and c.categories_id = cd.categories_id and cd.language_id='" . 

$languages_id ."' order by sort_order, cd.categories_name");




 while ($categories = tep_db_fetch_array($categories_query))  {
   if ($level{$categories['parent_id']} == "") { $level{$categories['parent_id']} = 0; }
   $level{$categories['categories_id']} = $level{$categories['parent_id']} + 1;

     $products_in_category = tep_count_products_in_category($categories['categories_id']);
     if ($products_in_category > 0) {

// Add category link to $categories_string
   for ($a=1; $a<$level{$categories['categories_id']}; $a++) {
     $categories_string .= "  ";
   }

   $categories_string .= '<a class="infoBoxContents" href="';

   $cPath_new = $cpath; 
   if ($level{$categories['parent_id']} > 0) {
     $cPath_new .= "_"; 
   }
   $cPath_new .= $categories['categories_id'];

   $cPath_new_text = "cPath=" . $cPath_new;
   
   $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new_text);
   $categories_string .= '">';

   if ($HTTP_GET_VARS['cPath']) {
     $selectedPath = split("_", $HTTP_GET_VARS['cPath']);
   }

   if (in_array($categories['categories_id'], $selectedPath)) { $categories_string .= '<b>'; }

   if ($level{$categories['categories_id']} <> 1) { $categories_string .= '-'; }

   $categories_string .= $categories['categories_name'];
   if ($COLLAPSABLE && tep_has_category_subcategories($categories['categories_id'])) { $categories_string .= ' ->'; } 




   if (in_array($categories['categories_id'], $selectedPath)) { $categories_string .= '</b>'; }

   $categories_string .= '</a>';

   if (SHOW_COUNTS == 'true') {
     $products_in_category = tep_count_products_in_category($categories['categories_id']);
     if ($products_in_category > 0) {
       $categories_string .= ' (' . $products_in_category . ')';
     }
   }

   $categories_string .= '<br>';


// If I have subcategories, get them and show them
   if (tep_has_category_subcategories($categories['categories_id'])) {

     if ($COLLAPSABLE) {
       if (in_array($categories['categories_id'], $selectedPath)) {
         tep_show_category($categories['categories_id'], $cPath_new, $COLLAPSABLE);
       }
     }
     else { tep_show_category($categories['categories_id'], $cPath_new, $COLLAPSABLE); }

   }

 }

}

}
?>


<!-- categories //-->
         <tr>
           <td>
<?php
 $info_box_contents = array();
 $info_box_contents[] = array('align' => 'left',
                              'text'  => BOX_HEADING_CATEGORIES
                             );
 new infoBoxHeading($info_box_contents, true, false);

 $categories_string = '';

// Expanded or collapsed sub-categories
// tep_show_category(<top category_id>, <top cpath>, <0 1=Collapsable tree, 0 0=static--show all>)
 tep_show_category(0,'',0); 

 $info_box_contents = array();
 $info_box_contents[] = array('align' => 'left',
                              'text'  => $categories_string
                             );
 new infoBox($info_box_contents);
?>
           </td>
         </tr>
<!-- categories_eof //-->

 

Enjoy :D

Link to comment
Share on other sites

Tony , thanks This part is working perfect.

 

However, when I click on a category from the menu (left), the stage (middle) gives all the categories under it regardless of items.

 

I think this part of code "lives" in /catalog/index.php

 

Any idea on that?

 

Thanks

 

-Arnon

Link to comment
Share on other sites

  • 2 years later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...