Page 3 of 9 FirstFirst 12345 ... LastLast
Results 21 to 30 of 83
  1. #21
    Join Date
    Sep 2012
    Location
    West Jefferson, NC
    Posts
    383
    Plugin Contributions
    0

    Default Re: How to hide categories with no active products

    Believe me, I will contribute financially if I can ever get people to start buying. I purchased a FB add and I have thousands of hits on the site from 16 states and 10 countries, thousands of likes in FB, but still no orders. Maybe by the shopping season people will remember the site and return for purchases. I'll buy another add just before shopping season and see if that is the ticket. It's a wait and see game from here on out. Thanks again.

  2. #22
    Join Date
    Sep 2012
    Location
    West Jefferson, NC
    Posts
    383
    Plugin Contributions
    0

    Default Re: How to hide categories with no active products

    Quote Originally Posted by Ajeh View Post
    In the Class category_tree.php the counts are made and the tree made for the sidebox ...

    With only the changes that I posted, for only the tpl_categories.php file, Only Categories that contain Active Products are showing ... NOTE: you need the Category Counts turned on in the settings to know which Categories to show or exclude, but the counts will still be hidden based on the code changes that I posted ...

    Have you additional changes that might be causing this to not work for you?
    Hi Ajeh,

    How do I hide categories, with no active products, in the horizontal/top page menu and subcategories/center page?

    Background:

    I've upgraded my cart to a responsive plug in...because most clicks are coming from mobile devices.

    I switched from using the category box to the horizontal menu across the top and showing subcategories in the center page area.

    The fix you gave me for hiding inactive products in the sidebox categories doesn't take care of the horizontal menu and center box subcategories. How do I fix that?

    Thanks for your help!

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

    Default Re: How to hide categories with no active products

    See if this will hide the empty categories from the category tabs ...

    Edit the file:
    /includes/modules/categories_tabs.php

    and add the code in RED:
    Code:
    while (!$categories_tab->EOF) {
    // bof: skip empty categories
    if (zen_count_products_in_category($categories_tab->fields['categories_id']) == 0) {
    // skip display of empty categories
    } else {
      // currently selected category
      if ((int)$cPath == $categories_tab->fields['categories_id']) {
        $new_style = 'category-top';
        $categories_tab_current = '<span class="category-subs-selected">' . $categories_tab->fields['categories_name'] . '</span>';
      } else {
        $new_style = 'category-top';
        $categories_tab_current = $categories_tab->fields['categories_name'];
      }
    
      // create link to top level category
      $links_list[] = '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . (int)$categories_tab->fields['categories_id']) . '">' . $categories_tab_current . '</a> ';
    }
    // eof: skip empty categories
      $categories_tab->MoveNext();
    }
    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!

  4. #24
    Join Date
    Sep 2012
    Location
    West Jefferson, NC
    Posts
    383
    Plugin Contributions
    0

    Default Re: How to hide categories with no active products

    Made changes and saved to my current template. Cleared cache. Empty / non-active categories still showing.

    Code:
    $links_list = array();
    while (!$categories_tab->EOF) {
    // bof: skip empty categories ADDED BY MIKE
    if (zen_count_products_in_category($categories_tab->fields['categories_id']) == 0) {
    // skip display of empty categories
    } else {
    
      // currently selected category
      if ((int)$cPath == $categories_tab->fields['categories_id']) {
        $new_style = 'category-top';
        $categories_tab_current = '<span class="category-subs-selected">' . $categories_tab->fields['categories_name'] . '</span>';
      } else {
        $new_style = 'category-top';
        $categories_tab_current = $categories_tab->fields['categories_name'];
      }
    
      // create link to top level category
      $links_list[] = '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . (int)$categories_tab->fields['categories_id']) . '">' . $categories_tab_current . '</a> ';
      }
    // eof: skip empty categories } ABOVE THIS LINE ADDED BY MIKE
      $categories_tab->MoveNext();
    }
    Do I need to undo the changes I made earlier in this thread to make this work?
    Last edited by mikeel100; 30 Jul 2014 at 12:28 AM. Reason: Added question at the end

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

    Default Re: How to hide categories with no active products

    Have you an URL to your domain where we can perhaps look at the layout of things?
    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!

  6. #26
    Join Date
    Sep 2012
    Location
    West Jefferson, NC
    Posts
    383
    Plugin Contributions
    0

    Default Re: How to hide categories with no active products

    I see what's wrong: Actual code needs to go in place of "// skip display of empty categories". I'll see if I can figure out the code. I use PDO programming with php and mysql. Will that work here?

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

    Default Re: How to hide categories with no active products

    Actually, I used the exact code that I posted, with the comments and no changes, to block the empty categories ... this is why it might help to see your site and know which categories should not be showing in the category tabs ...
    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!

  8. #28
    Join Date
    Sep 2012
    Location
    West Jefferson, NC
    Posts
    383
    Plugin Contributions
    0

    Default Re: How to hide categories with no active products

    Quote Originally Posted by Ajeh View Post
    Actually, I used the exact code that I posted, with the comments and no changes, to block the empty categories ... this is why it might help to see your site and know which categories should not be showing in the category tabs ...
    https://jestcountrystuff.com/index.p...dex&cPath=1563

    Camping and Trailer Hitch Hammakas are empty categories.

    I tried the code you sent with category counts turned off and on...no joy.

    I also tried removing your recommended changes (earlier in this thread)...no joy.

    I am using 1.5.1 on Godaddy with Responsive Classic Template, EP4, UPS, dbBackup, Wishlists, and I added Social Share buttons manually. None of those should be messing with categories (I think)...

    Thanks for your help!
    Last edited by Ajeh; 30 Jul 2014 at 01:55 PM. Reason: remove zenid; never post in emails, newsletters or forums

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

    Default Re: How to hide categories with no active products

    It sounds like what you really want to do is not show the Empty Categories in the middle of the page ...

    To do that, you can edit the module:
    /includes/modules/category_row.php

    and add the code in RED:
    Code:
    // bof: hide empty categories
    if (zen_count_products_in_category($categories->fields['categories_id']) == 0) {
      // skip empty category
    } 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'] . ' ' . $countContentProduct . '</a>');
    }
    // bof: hide empty categories
    
        $col ++;
        if ($col > (MAX_DISPLAY_CATEGORIES_PER_ROW -1)) {
    NOTE: That other code I gave you is not a good solution at all for the Category Tabs, so I would remove it ...
    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. #30
    Join Date
    Sep 2012
    Location
    West Jefferson, NC
    Posts
    383
    Plugin Contributions
    0

    Default Re: How to hide categories with no active products

    I'll give that a shot...

    I wrote my own script to use during my catalog update that will take care of my issues.

    PHP Code:
    <?php
        $hostname 
    "xxxxxxxxxxxxxx";
        
    $username "xxxxxxxxxxxxx";
        
    $dbname "xxxxxxxxxxxxxx";
        
    $password "xxxxxxxxxxxx";
        
        
    $fail_point "Connecting to db";
        
        
    $dbh = new PDO("mysql:host=$hostname;dbname=$dbname;charset=utf8"$username$password);
            
        
    $dbh->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);        

        try
        {    

        
    $fail_point "FIX QUANTITIES EXPONENTIAL AMOUNTS";
        
        
    $query = ("UPDATE zen_products SET products_quantity = 10 WHERE products_quantity LIKE '%+%'");
        
    $stmt $dbh->prepare($query);
        
    $stmt->execute();

        
    $fail_point "RESET QUANTITIES <1 TO 0";
        
        
    $query = ("UPDATE zen_products SET products_quantity = 0 WHERE products_quantity < 1");
        
    $stmt $dbh->prepare($query);
        
    $stmt->execute();
        
        
    $fail_point "GET QUANTITY TOTALS FROM PRODUCTS TABLE AND ADJUST STATUS";
        
        
    //THIS HIDES CATEGORIES WITH PRODUCTS IN THEM IN THE BOTTOM CATEGORY LEVEL
        
        
    foreach ($dbh->query("SELECT DISTINCT parent_id, categories_id FROM zen_categories
        WHERE categories_id IN (SELECT master_categories_id FROM zen_products WHERE products_quantity < 1)"
    )as $unique_record)
        {
            
    $unique_p_id $unique_record['parent_id'];
            
    $unique_c_id $unique_record['categories_id'];
            
            
    $fail_point "Counting p2c";
                    
            
    $total $dbh->query("SELECT SUM(products_quantity) FROM zen_products 
            WHERE zen_products.master_categories_id = 
    $unique_c_id");
            
    $myQty $total->fetchColumn();
            
    //echo "Category ID - ".$unique_c_id." Total - ".$myQty."<br>";

            
    $fail_point "Changing status";
            
            if (
    $myQty == 0)
            {
                
    $query = ("UPDATE zen_categories SET categories_status = 0 WHERE parent_id = $unique_p_id 
                AND categories_id = 
    $unique_c_id");
                
    $stmt $dbh->prepare($query);
                
    $stmt->execute();
                
    //echo "Parent ID - ".$unique_p_id." - Status set to 0 <br><br>";
            

            else 
            {
                
    $query = ("UPDATE zen_categories SET categories_status = 1 WHERE parent_id = $unique_p_id 
                AND categories_id = 
    $unique_c_id ");
                
    $stmt $dbh->prepare($query);
                
    $stmt->execute();
                
    //echo $unique_p_id." Status set to 1 <br><br>";
            
    }
        }


        
    //HIDE EMPTY CATEGORIES

        
    foreach ($dbh->query("SELECT DISTINCT parent_id, categories_id FROM zen_categories
        WHERE categories_id NOT IN (SELECT master_categories_id FROM zen_products)"
    )as $unique_record)
        {
            
    $unique_p_id $unique_record['parent_id'];
            
    $unique_c_id $unique_record['categories_id'];
            

            
    $test $dbh->query("SELECT categories_id FROM zen_categories 
            WHERE 
    $unique_c_id IN (SELECT parent_id FROM zen_categories)");
            
    $subcategories $test->fetchColumn();
            
    $count $test->rowCount();
            
    //echo "Category ID - ".$unique_c_id." Subcategories - ".$subcategories."<br>";
            
            
    $fail_point "Changing status";
            
            if (
    $subcategories == 0)
            {
                
    $query = ("UPDATE zen_categories SET categories_status = 0 WHERE categories_id = $unique_c_id");
                
    $stmt $dbh->prepare($query);
                
    $stmt->execute();
                
    //echo "Parent ID - ".$unique_c_id." - Status set to 0 <br><br>";
            

            else 
            {
                
    $query = ("UPDATE zen_categories SET categories_status = 1 WHERE categories_id = $unique_c_id ");
                
    $stmt $dbh->prepare($query);
                
    $stmt->execute();
                
    //echo $unique_c_id." Status set to 1 <br><br>";
            
    }

        }    

        
    //HIDE UNCATEGORIZED, NUDES, AND ANY OTHER CATEGORIES YOU DO NOT WANT SHOWING...NOT BASED ON QUANTITY

        
    $fail_point "Hiding other categories";
        
        
    $query = ("UPDATE zen_categories SET categories_status = 0 WHERE categories_id = 1539 OR categories_id = 1");
        
    $stmt $dbh->prepare($query);
        
    $stmt->execute();

        } 
        catch (
    PDOException $e) {
            echo 
    "Hiding categories failed to process." $fail_point $e->getMessage() . "<br/>";
            die();
        }
    ?>
    If you see harm in using this instead, let me know.

    Thanks.

 

 
Page 3 of 9 FirstFirst 12345 ... LastLast

Similar Threads

  1. v150 how do i hide sub categories with no products listed
    By alibaba99 in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 28 Jan 2017, 06:19 PM
  2. Hide Categories with 0 Products
    By Semenek in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 4 Sep 2010, 05:44 PM
  3. Hide categories/subcategories with no products
    By earthone in forum Basic Configuration
    Replies: 0
    Last Post: 22 Jul 2010, 09:38 PM
  4. Active products in categories box
    By ouxly40 in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 26 Sep 2007, 11:46 AM
  5. How to hide sub-categories with no active products?
    By donplay in forum Setting Up Categories, Products, Attributes
    Replies: 5
    Last Post: 29 Aug 2007, 08:20 PM

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