Forums / Basic Configuration / Excluding a product or category from best selling list

Excluding a product or category from best selling list

Locked

Views: 11,576

Results 21 to 34 of 34
This thread is locked. New replies are disabled.
9 Feb 2009, 7:32 AM
#21
fontgarden avatar

fontgarden

New Zenner

Join Date:
Feb 2007
Posts:
10
Plugin Contributions:
0

Excluding a product or category from best selling list

I got a MySQL error when trying the above fix:

1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'p.product_is_free != 1 order by p.products_ordered ' at line 10
in:
[select distinct p.products_id, pd.products_name, p.products_ordered                              from products p, products_description pd, products_to_categories p2c, categories c                              where p.products_status = '1'                              and p.products_ordered > 0                              and p.products_id = pd.products_id                              and pd.language_id = '1'                              and p.products_id = p2c.products_id                              and p2c.categories_id = c.categories_id                              and '67' in (c.categories_id, c.parent_id) 				     p.product_is_free != 1                              order by p.products_ordered desc, pd.products_name                              limit 20]

What did I do wrong? :oops:

30 Aug 2009, 4:45 AM
#22
sweetikins avatar

sweetikins

New Zenner

Join Date:
Feb 2009
Location:
Melbourne, Australia
Posts:
85
Plugin Contributions:
0

Re: Excluding a product or category from best selling list

Ajeh:

Let's say you want to toss out all products in categories_id 42 ...

That would now use the master_categories_id 42 in the products table so you should be able to use:

$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.master_categories_id != 42
order by p.products_ordered desc, pd.products_name
limit " . MAX_DISPLAY_BESTSELLERS;

> 
> Note: this assumes all products that should not display use the same Category and that Category is "owns" these Products which would reflect that in that the master_categories_id of all of these Products would be the same ...
> 
> In this example:
> ```php
                             and p.master_categories_id != 42

this is the key to the block ...

Hiya, i was wondering if it is possible to exclude certain products for the bestsellers list? there is 10 of them and they are in different catagories. They where givin as freebies for 3 days before going up for sale and so there for they have taken up all the space on the bestsellers box

3 Sep 2009, 3:06 PM
#23
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Excluding a product or category from best selling list

Let's say you didn't want products_id 199 and 26 to show in the Best sellers sidebox ...

You could customize the best_sellers.php sidebox module with something like:

    if (isset($current_category_id) && ($current_category_id > 0)) {
      $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 (199, 26)" . "

                             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 (199, 26)" . "

                             order by p.products_ordered desc, pd.products_name
                             limit " . MAX_DISPLAY_BESTSELLERS;

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

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!]
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!

22 Sep 2009, 5:42 AM
#24
sweetikins avatar

sweetikins

New Zenner

Join Date:
Feb 2009
Location:
Melbourne, Australia
Posts:
85
Plugin Contributions:
0

Re: Excluding a product or category from best selling list

Thank you so much for the reply, i will give it a go and post back with a result xoxo

22 Sep 2009, 6:12 AM
#25
sweetikins avatar

sweetikins

New Zenner

Join Date:
Feb 2009
Location:
Melbourne, Australia
Posts:
85
Plugin Contributions:
0

Re: Excluding a product or category from best selling list

YAYYYYYYYYYYYY ok all fixed thank you ever so much :clap:

22 Sep 2009, 2:54 PM
#26
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Excluding a product or category from best selling list

You are most welcome ... thanks for the update that this worked for you ... :smile:

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!]
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 Oct 2010, 5:38 PM
#27
fireflyz avatar

fireflyz

New Zenner

Join Date:
May 2007
Location:
Los Angeles
Posts:
89
Plugin Contributions:
0

Re: Excluding a product or category from best selling list

Hi Ajeh,
I followed your directions below and I see no changes to the bestseller sidebox. I did use the override and the products are not free.

zen 1.3.8

Thank you for your help!

Ajeh:

Let's say you didn't want products_id 199 and 26 to show in the Best sellers sidebox ...

You could customize the best_sellers.php sidebox module with something like:

if (isset($current_category_id) && ($current_category_id > 0)) {
  $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 (199, 26)" . "

                         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 (199, 26)" . "

                         order by p.products_ordered desc, pd.products_name
                         limit " . MAX_DISPLAY_BESTSELLERS;

  $best_sellers = $db->Execute($best_sellers_query);
}
6 Oct 2010, 6:08 PM
#28
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Excluding a product or category from best selling list

Check the products_id for the Products that you want to exclude and make sure you have them where you see the 199, 26 ...

Check that your file actually is updated on the server with these changes in your:
/includes/modules/sideboxes/your_template_dir/best_sellers.php

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!]
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 Oct 2010, 6:09 PM
#29
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Excluding a product or category from best selling list

NOTE: there are 2 places in the code for the products_id to be set ...

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!]
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 Oct 2010, 7:53 PM
#30
fireflyz avatar

fireflyz

New Zenner

Join Date:
May 2007
Location:
Los Angeles
Posts:
89
Plugin Contributions:
0

Re: Excluding a product or category from best selling list

Ajeh,
I have uploaded it to the correct folder and made the changes in two section. Below is the complete code. Could it because the categories are under a hidden category? The categories are setup like this:
Categories / Products - Top > Brand Names (HIDDEN) > Categories (52, 43)

Thanks a lot!

<?php
/**
 * best_sellers sidebox - displays selected number of (usu top ten) best selling products
 *
 * @package templateSystem
 * @copyright Copyright 2003-2005 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: best_sellers.php 2718 2005-12-28 06:42:39Z drbyte $
 */

// test if box should display
  $show_best_sellers= false;

  if (isset($_GET['products_id'])) {
    if (isset($_SESSION['customer_id'])) {
      $check_query = "select count(*) as count
                      from " . TABLE_CUSTOMERS_INFO . "
                      where customers_info_id = '" . (int)$_SESSION['customer_id'] . "'
                      and global_product_notifications = '1'";

      $check = $db->Execute($check_query);

      if ($check->fields['count'] > 0) {
        $show_best_sellers= true;
      }
    }
  } else {
    $show_best_sellers= true;
  }

  if ($show_best_sellers == true) {
    if (isset($current_category_id) && ($current_category_id > 0)) {
      $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 (52, 43)" . "

                             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 (52, 43)" . "

                             order by p.products_ordered desc, pd.products_name
                             limit " . MAX_DISPLAY_BESTSELLERS;

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

    if ($best_sellers->RecordCount() >= MIN_DISPLAY_BESTSELLERS) {
      $title =  BOX_HEADING_BESTSELLERS;
      $box_id =  'bestsellers';
      $rows = 0;
      while (!$best_sellers->EOF) {
        $rows++;
        $bestsellers_list[$rows]['id'] = $best_sellers->fields['products_id'];
        $bestsellers_list[$rows]['name']  = $best_sellers->fields['products_name'];
        $best_sellers->MoveNext();
      }

      $title_link = false;
      require($template->get_template_dir('tpl_best_sellers.php',DIR_WS_TEMPLATE, $current_page_base,'sideboxes'). '/tpl_best_sellers.php');
      $title =  BOX_HEADING_BESTSELLERS;
      require($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE, $current_page_base,'common') . '/' . $column_box_default);
    }
  }
?>
6 Oct 2010, 8:05 PM
#31
fireflyz avatar

fireflyz

New Zenner

Join Date:
May 2007
Location:
Los Angeles
Posts:
89
Plugin Contributions:
0

Re: Excluding a product or category from best selling list

Ajeh,
Never mind! The template file apparently wasn't uploaded completely. I re-uploaded the tpl_best_sellers.php to custom folder and is working like a charm!

Thank you so much!

6 Oct 2010, 8:29 PM
#32
fireflyz avatar

fireflyz

New Zenner

Join Date:
May 2007
Location:
Los Angeles
Posts:
89
Plugin Contributions:
0

Re: Excluding a product or category from best selling list

Ajeh,
Sorry, I spoke too soon. The products that I don't want, they show sometime depending on the category clicked on the website. But they are still there. :frusty:

thanks!

6 Oct 2010, 8:48 PM
#33
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Excluding a product or category from best selling list

So far, I cannot reproduce this issue ...

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!]
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!

14 Nov 2010, 3:06 AM
#34
caroleas avatar

caroleas

Totally Zenned

Join Date:
Feb 2009
Posts:
896
Plugin Contributions:
0

Re: Excluding a product or category from best selling list

Thanks to the OP and the help of those who replied, i got this done on my store too (never thought it was feasible so i never asked!).