Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    Oct 2015
    Posts
    30
    Plugin Contributions
    0

    link problem How to hide empty categories automatically?

    Is there easy way to automatically hide category that's empty (= all products sold out)? I know I can hide them manually, but my site has lot of categories and it's rather difficult to keep track on all of them.

  2. #2
    Join Date
    Jul 2012
    Posts
    16,718
    Plugin Contributions
    17

    Default Re: How to hide empty categories automatically?

    Quote Originally Posted by Miru View Post
    Is there easy way to automatically hide category that's empty (= all products sold out)? I know I can hide them manually, but my site has lot of categories and it's rather difficult to keep track on all of them.
    While the associated links at the bottom of this page (not shown until posting) may help, the link within the first points to a solution specific to 1.5.4: https://www.zen-cart.com/showthread....47#post1265047
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Oct 2015
    Posts
    30
    Plugin Contributions
    0

    Default Re: How to hide empty categories automatically?

    Thanks, I will test that.

  4. #4
    Join Date
    Oct 2015
    Posts
    30
    Plugin Contributions
    0

    Default Re: How to hide empty categories automatically?

    My friend said (and tested and it didn't work) that the code is made for 1.5.3 version of Zen and won't work on new one.

  5. #5
    Join Date
    Dec 2011
    Location
    Wisconsin, USA
    Posts
    674
    Plugin Contributions
    21

    Default Re: How to hide empty categories automatically?

    Did you try?
    Configuration -> Layout Settings -> Categories with 0 Products Status

  6. #6
    Join Date
    Oct 2015
    Posts
    30
    Plugin Contributions
    0

    Default Re: How to hide empty categories automatically?

    Yes, it's marked "on", but doesn't work.

  7. #7
    Join Date
    Dec 2011
    Location
    Wisconsin, USA
    Posts
    674
    Plugin Contributions
    21

    Default Re: How to hide empty categories automatically?

    Quote Originally Posted by Miru View Post
    Yes, it's marked "on", but doesn't work.
    What template are you using sometimes certain templates override this. If you switch to classic does the problem still exist?

  8. #8
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: How to hide empty categories automatically?

    There is a difference between turning off Categories with 0 Products and turning off Categories where there ARE Products but all are marked as products_status = 0 ... the switch works to disable the counts when the count of active products is 0 ...

    I am almost done with writing one for v1.5.4 ...
    Last edited by Ajeh; 28 Oct 2015 at 10:37 PM.
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  9. #9
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: How to hide empty categories automatically?

    To have Categories automatically disappear when Products are set to products_status = 0 in Zen Cart v1.5.4, use the templates and overrides directory for the following files with the code marked in RED:
    /includes/modules/categories_tabs.php
    Code:
      // create link to top level category
        // skip empty or status off categories
        if ((CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$categories_tab->fields['categories_id']) == 0)) {
        // skip empty or status off categories
        } else {
      $links_list[] = '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . (int)$categories_tab->fields['categories_id']) . '">' . $categories_tab_current . '</a> ';
        }
      $categories_tab->MoveNext();
    }
    /includes/modules/category_row.php
    Code:
        //    $categories->fields['products_name'] = zen_get_products_name($categories->fields['products_id']);
        if ((CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$categories->fields['categories_id']) == 0)) {
        // skip empty or status off categories
        } else {
            $list_box_contents[$row][$col] = array('params' => 'class="categoryListBoxContents"' . ' ' . 'style="width:' . $col_width . '%;"',
                                                 'text' => '<a href="' . zen_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . zen_image(DIR_WS_IMAGES . $categories->fields['categories_image'], $categories->fields['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br />' . $categories->fields['categories_name'] . '</a>');
    
          $col ++;
          if ($col > (MAX_DISPLAY_CATEGORIES_PER_ROW -1)) {
            $col = 0;
            $row ++;
          }
        }
        $categories->MoveNext();
      }
    }
    /includes/templates/template_default/sideboxes/tpl_categories.php
    Code:
      $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";
      for ($i=0;$i<sizeof($box_categories_array);$i++) {
        if ((CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && $box_categories_array[$i]['count'] == 0) || zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
          // skip if this is for the document box (==3)
          // skip empty or status off categories
          continue;
        }
        switch(true) {
    // to make a specific category stand out define a new class in the stylesheet example: A.category-holiday
    /includes/classes/site_map.php
    Code:
             $categories = $db->Execute($categories_query);
             while (!$categories->EOF) {
            // skip empty or status off categories
            if (!(CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$categories->fields['categories_id']) == 0)) {
               $this->data[$categories->fields['parent_id']][$categories->fields['categories_id']] = array('name' => $categories->fields['categories_name'], 'count' => 0);
            }
               $categories->MoveNext();
             }
       }
    And just a little below that:
    Code:
       function buildBranch($parent_id, $level = 0, $parent_link = '') {
        $result = $this->parent_group_start_string;
    
        if (isset($this->data[$parent_id])) {
          foreach ($this->data[$parent_id] as $category_id => $category) {
            if (CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$category_id) == 0) {
              // skip empty or status off categories
              continue;
            }
            $category_link = $parent_link . $category_id;
            $result .= $this->child_start_string;
    And to control this setting add to the database via the Tools ... Install SQL Patches:
    Code:
    INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Categories with Inactive Products Status', 'CATEGORIES_PRODUCTS_INACTIVE_HIDE', '0', 'Hide Categories with Inactive Products?<br />0= off<br />1= on', 19, 30, 'zen_cfg_select_option(array(\'0\', \'1\'), ', now());
    This setting then will be found in the Configuration ... Layout Settings ...
    Categories with Inactive Products Status
    Hide Categories with Inactive Products?
    0= off
    1= on
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  10. #10
    Join Date
    Nov 2009
    Location
    Aransas Pass, TX
    Posts
    101
    Plugin Contributions
    1

    Default Re: How to hide empty categories automatically?

    Works great on ver 1.5.6a

    Thanks!

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v151 URI Mapping - How do I automatically add mappings for EXISTING Categories/Products?
    By Adrian Ciocîrlan in forum All Other Contributions/Addons
    Replies: 1
    Last Post: 8 Jun 2016, 02:14 PM
  2. v139h How to automatically turn off sold out categories
    By joew36 in forum General Questions
    Replies: 4
    Last Post: 24 Jul 2015, 01:17 PM
  3. Replies: 10
    Last Post: 3 Oct 2013, 03:43 PM
  4. How to hide ampty categories
    By marknew in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 24 Jan 2011, 03:36 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR