Page 4 of 9 FirstFirst ... 23456 ... LastLast
Results 31 to 40 of 83
  1. #31
    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
    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 ...
    Actually, I want to hide subcategories where all products are inactive and subcategories where no products are in them.

    Didn't work...it hid the empty categories but it also hid some categories with products active. It also left random blank areas where categories should be.

    The end of my categories_tab page code looks different than yours. . ' ' . $countContentProduct is missing right before </a>.

    PHP Code:
    $categories->fields['categories_name'] . '</a>');

        
    $col ++;
        if (
    $col > (MAX_DISPLAY_CATEGORIES_PER_ROW -1)) {
          
    $col 0;
          
    $row ++;
        }
        
    $categories->MoveNext();
      }

    I don't know if that has anything to do with it since I'm no guru on this code.

    Thanks again.
    Last edited by mikeel100; 31 Jul 2014 at 04:06 AM. Reason: Explaination...

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

    Default Re: How to hide categories with no active products

    Deleted.

  3. #33
    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 mikeel100 View Post
    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.
    This code will only hide the BOTTOM LEVEL SUBCATEGORIES.

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

    Default Re: How to hide categories with no active products

    Sorry, I ended the IF incorrectly ...

    Try this code in RED:
    Code:
    // bof: hide empty categories
    if (zen_count_products_in_category($categories->fields['categories_id']) == 0) {
      // skip empty category
      echo 'Skipped empty category: ' . $categories->fields['categories_name'] . '<br>';
    } 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>');
    
    
        $col ++;
        if ($col > (MAX_DISPLAY_CATEGORIES_PER_ROW -1)) {
          $col = 0;
          $row ++;
        }
    }
    // eof: hide empty categories
        $categories->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!

  5. #35
    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
    Sorry, I ended the IF incorrectly ...

    Try this code in RED:
    Code:
    // bof: hide empty categories
    if (zen_count_products_in_category($categories->fields['categories_id']) == 0) {
      // skip empty category
      echo 'Skipped empty category: ' . $categories->fields['categories_name'] . '<br>';
    } 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>');
    
    
        $col ++;
        if ($col > (MAX_DISPLAY_CATEGORIES_PER_ROW -1)) {
          $col = 0;
          $row ++;
        }
    }
    // eof: hide empty categories
        $categories->MoveNext();
      }
    }
    You are a genius and I really appreciate the help!

    I like the echo trick to show which categories got hidden!

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

    Default Re: How to hide categories with no active products

    Just comment that out after testing ...

    Thanks for the update that this is working for you ...
    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!

  7. #37
    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
    Just comment that out after testing ...

    Thanks for the update that this is working for you ...
    Comment what out?

  8. #38
    Join Date
    Jan 2007
    Location
    Los Angeles, California, United States
    Posts
    10,023
    Plugin Contributions
    32

    Default Re: How to hide categories with no active products

    Quote Originally Posted by mikeel100 View Post
    Comment what out?
    The echo statement..
    My Site - Zen Cart & WordPress integration specialist
    I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

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

    Default Re: How to hide categories with no active products

    Doh, yes, I had already done that. Thanks.

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

    Default Re: How to hide categories with no active products

    This does work in 1.5.3 ... please consider adding this to the next upgrade package.

 

 
Page 4 of 9 FirstFirst ... 23456 ... 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