If this is your first visit, check our documentation. To post, register or login.
Forums / Customizing the Look of Your Shop / Templates, Stylesheets, Page Layout / Maintaining uniform best sellers list, regardless of category

Maintaining uniform best sellers list, regardless of category

Locked

Started by susan767 on 21 Feb 2009, 3:15 AM · Views: 1,762

Results 1 to 6 of 6
This thread is locked. New replies are disabled.
21 Feb 2009, 3:15 AM
#1
susan767 avatar

susan767

New Zenner

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

Post #1 by susan767

I noticed that the best sellers box lists only the items in the category I am currently in.

Instead, I would like it to display a uniform list of best sellers regardless of the category that the customer is in.

Would it be possible to achieve this by changing best_sellers.php as follows?

<?php

  $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) {
     
      $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
                             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);
    }
  }
?>

Thanks,

Susan

21 Feb 2009, 3:43 AM
#2
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Post #2 by bunyip

Yes, you're on the right track and your modification will work.
I will make one comment though, and it's nothing to do with your code but with the original - I don't follow the reasoning behind the first nest of if statements to test if the sidebox should display.

As I follow the logic, the sidebox will display on every page EXCEPT on a product info page, but will display on a product_info page if the customer has logged in and has previously selected via their account pages to have global notifications set to on. What's that got to do with displaying the best sellers sidebox? My guess is: nothing - it just seems that the original best_sellers sidebox code was copied from the product_notifications sidebox and this issue has never been noticed before.

Personally, I'd just delete that whole first logic test section, leaving you with just:

      $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
                             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);
    }

Neville
An assumption is what you arrive at when you get tired of thinking...

21 Feb 2009, 4:29 AM
#3
susan767 avatar

susan767

New Zenner

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

Post #3 by susan767

Thanks, bunyip

I agree and have removed the first section as you suggested.

Susan

3 Jan 2010, 5:08 PM
#4
geurenhuis avatar

geurenhuis

New Zenner

Join Date:
Nov 2009
Location:
Netherlands
Posts:
21
Plugin Contributions:
0

Post #4 by geurenhuis

Wow the code seems pretty helpfull since i had the same issue.

The code offered by suzan767 helped a lot! The bestsellers sidebox stays visible almost all the time.

Indeed the bestsellers box won't show on product_info pages.
I can't seem to integrate the piece of code by bunyip into the best_sellers.php file.

My php coding skills are minimal so i was wondering if someone has the full code.

So that the bestsellers sidebox is showing all the time, including when visiting a product_info page!

Thank you in advance!

Yours, Peter de Leeuw

3 Jan 2010, 5:31 PM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Post #5 by gjh42

You would be deleting everything from
$show_best_sellers= false;
to
if ($show_best_sellers == true) {
and the
}
at the bottom of Susan's code. You may or may not want the <?php and ?> at the beginning and end of this snippet.

You would replace the code that begins and ends like Susan's with the stripped-down version.

3 Jan 2010, 6:36 PM
#6
geurenhuis avatar

geurenhuis

New Zenner

Join Date:
Nov 2009
Location:
Netherlands
Posts:
21
Plugin Contributions:
0

Post #6 by geurenhuis

Wow that worked great!
The bestsellers will be shown even on product_info pages.

Thank you so much!

cheers