Zen Cart How to Exclude Specific Products from Best Sellers

Each time a customer makes a purchase from your zen cart store, the data is stored in the database. This allows zen cart to compile a list of best selling products. If you have certain products that you do not want to show on your stores best seller list (for example a limited time or quantity product, or a free offer product), you will need to add some custom php coding to exclude them from the list. This Easy Help Zen Cart Tutorial will show you how to add some custom code to exclude products from your stores best sellers list.

In your favorite plain text editor open the includes/modules/sideboxes/override/best_sellers.php file. If there is not already an override for this file you can create one by copying the includes/modules/sideboxes/best_sellers.php to includes/modules/sideboxes/override/best_sellers.php.

Find the Select statement near the top of the file:


      $best_sellers_query = "select distinct p.products_id, pd.products_name, p.products_ordered
                             from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, "
                                    . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c
                             where p.products_status = '1'
                             and p.products_ordered > 0
                             and p.products_id = pd.products_id
                             and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                             and p.products_id = p2c.products_id
                             and p2c.categories_id = c.categories_id
                             and '" . (int)$current_category_id . "' in (c.categories_id, c.parent_id)
                             order by p.products_ordered desc, pd.products_name";

      $best_sellers_query .= $limit;
      $best_sellers = $db->Execute($best_sellers_query);
    } else {
      $best_sellers_query = "select distinct p.products_id, pd.products_name, p.products_ordered
                             from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
                             where p.products_status = '1'
                             and p.products_ordered > 0
                             and p.products_id = pd.products_id
                             and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                             order by p.products_ordered desc, pd.products_name";

      $best_sellers_query .= $limit;
      $best_sellers = $db->Execute($best_sellers_query);
    }

and change it to this:


    $best_sellers_query = "select distinct p.products_id, pd.products_name, p.products_ordered 
                             from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " 
                                    . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c 
                             where p.products_status = '1' 
                             and p.products_ordered > 0 
                             and p.products_id = pd.products_id 
                             and pd.language_id = '" . (int)$_SESSION['languages_id'] . "' 
                             and p.products_id = p2c.products_id 
                             and p2c.categories_id = c.categories_id 
                             and '" . (int)$current_category_id . "' in (c.categories_id, c.parent_id) 
                             and p.products_id not in (10, 12) 
                             order by p.products_ordered desc, pd.products_name 
                             limit " . MAX_DISPLAY_BESTSELLERS; 

      $best_sellers = $db->Execute($best_sellers_query); 

    } else { 
      $best_sellers_query = "select distinct p.products_id, pd.products_name, p.products_ordered 
                             from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd 
                             where p.products_status = '1' 
                             and p.products_ordered > 0 
                             and p.products_id = pd.products_id 
                             and pd.language_id = '" . (int)$_SESSION['languages_id'] . "' 
                             and p.products_id not in (10, 12) 
                             order by p.products_ordered desc, pd.products_name 
                             limit " . MAX_DISPLAY_BESTSELLERS; 

      $best_sellers = $db->Execute($best_sellers_query); 
    }  

This example shows products with id’s 10 and 12 being excluded from the Best Sellers list.

Save your changes and upload the file to your server making sure that you overwrite the file already on your server.

If you need help with your zen cart web site please contact us for a quote.

zen cart plus picaflor azul equals success

Leave a Reply