Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Display Best Sellers instead of New Products ?


Marvin Miller

Recommended Posts

Search the addons area for a best sellers addon that meets your requirements and follow the install instructions supplied.

 

You may also finf a featured products addon or two which will allow you to choose what shows in the modules boxes.

 

The addons area can be found by hovering over the website link at the top left of this page and then clicking on addons. You can use the search function to narrow down your search.A search on google or other search engine will also find what you require.

REMEMBER BACKUP, BACKUP AND BACKUP

Link to comment
Share on other sites

Hi Steve;

 

I looked there and I could find nothing relevant nor anything remotely current. I didn't even think it would require a code change - I was kind of hoping something that simple was in the admin section and perhaps I missed it. All I'm after is instead of the home page displaying what's new, display the best sellers instead.

 

Maybe I'm not doing a search with the right keywords. All I seem to find are things from 2002, or thereabouts....

Best & Thanks;
Marvin
----------------------
osCommerce 2.3.3.4 

Link to comment
Share on other sites

Odd....I managed to find a post about this from 2013;

 

http://www.oscommerce.com/forums/topic/392265-best-sellers-page/

 

And it looks like it should work but I could not detect any change at all. The home page still showed all the New Products added instead of best sellers.

 

I'm replacing the code in products_new.php with the code from the thread above. Is that the page that's called when someone hits the home page and it displays New Products added since..?

Best & Thanks;
Marvin
----------------------
osCommerce 2.3.3.4 

Link to comment
Share on other sites

Odd....I managed to find a post about this from 2013;

 

http://www.oscommerce.com/forums/topic/392265-best-sellers-page/

 

And it looks like it should work but I could not detect any change at all. The home page still showed all the New Products added instead of best sellers.

 

I'm replacing the code in products_new.php with the code from the thread above. Is that the page that's called when someone hits the home page and it displays New Products added since..?

 

No. The call is for includes/modules/new_products.php

Link to comment
Share on other sites

You have to add p.products_ordered to both queries inside the new_products.php and then end both queries with something like this.

 order by p.products_ordered desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
Link to comment
Share on other sites

Here's a quick hack:

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2014 osCommerce

  Released under the GNU General Public License
*/

  
        if (isset($current_category_id) && ($current_category_id > 0)) {
        $best_sellers_query = tep_db_query("select distinct p.products_id, pd.products_name 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)$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 limit " . MAX_DISPLAY_BESTSELLERS);
      } else {
        $best_sellers_query = tep_db_query("select distinct p.products_id, pd.products_name 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)$languages_id . "' order by p.products_ordered desc, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS);
      }

  $num_best_sellers = tep_db_num_rows($best_sellers_query);

  if ($num_best_sellers > 0) {

    $best_sellers_content = NULL;

    while ($best_sellers = tep_db_fetch_array($best_sellers_query)) {
      $best_sellers_content .= '<div class="col-sm-6 col-md-4">';
      $best_sellers_content .= '  <div class="thumbnail equal-height">';
      $best_sellers_content .= '    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $best_sellers['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $best_sellers['products_image'], $best_sellers['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
      $best_sellers_content .= '    <div class="caption">';
      $best_sellers_content .= '      <p class="text-center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $best_sellers['products_id']) . '">' . $best_sellers['products_name'] . '</a></p>';
      $best_sellers_content .= '      <hr>';
      $best_sellers_content .= '      <p class="text-center">' . $currencies->display_price($best_sellers['products_price'], tep_get_tax_rate($best_sellers['products_tax_class_id'])) . '</p>';
      $best_sellers_content .= '      <div class="text-center">';
      $best_sellers_content .= '        <div class="btn-group">';
      $best_sellers_content .= '          <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'products_id=' . $best_sellers['products_id']) . '" class="btn btn-default" role="button">' . SMALL_IMAGE_BUTTON_VIEW . '</a>';
      $best_sellers_content .= '          <a href="' . tep_href_link($PHP_SELF, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $best_sellers['products_id']) . '" class="btn btn-success" role="button">' . SMALL_IMAGE_BUTTON_BUY . '</a>';
      $best_sellers_content .= '        </div>';
      $best_sellers_content .= '      </div>';
      $best_sellers_content .= '    </div>';
      $best_sellers_content .= '  </div>';
      $best_sellers_content .= '</div>';
    }
?>

  <h3><?php echo sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')); ?></h3>

  <div class="row">
    <?php echo $best_sellers_content; ?>
  </div>

<?php
  }
?>

You will still have to make some changes eg. TABLE_HEADING_NEW_PRODUCTS

Link to comment
Share on other sites

with image added to the query:

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2014 osCommerce

  Released under the GNU General Public License
*/

  
        if (isset($current_category_id) && ($current_category_id > 0)) {
        $best_sellers_query = tep_db_query("select distinct p.products_id, p.products_image, pd.products_name 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)$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 limit " . MAX_DISPLAY_BESTSELLERS);
      } else {
        $best_sellers_query = tep_db_query("select distinct p.products_id, p.products_image, pd.products_name 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)$languages_id . "' order by p.products_ordered desc, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS);
      }

  $num_best_sellers = tep_db_num_rows($best_sellers_query);

  if ($num_best_sellers > 0) {

    $best_sellers_content = NULL;

    while ($best_sellers = tep_db_fetch_array($best_sellers_query)) {
      $best_sellers_content .= '<div class="col-sm-6 col-md-4">';
      $best_sellers_content .= '  <div class="thumbnail equal-height">';
      $best_sellers_content .= '    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $best_sellers['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $best_sellers['products_image'], $best_sellers['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
      $best_sellers_content .= '    <div class="caption">';
      $best_sellers_content .= '      <p class="text-center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $best_sellers['products_id']) . '">' . $best_sellers['products_name'] . '</a></p>';
      $best_sellers_content .= '      <hr>';
      $best_sellers_content .= '      <p class="text-center">' . $currencies->display_price($best_sellers['products_price'], tep_get_tax_rate($best_sellers['products_tax_class_id'])) . '</p>';
      $best_sellers_content .= '      <div class="text-center">';
      $best_sellers_content .= '        <div class="btn-group">';
      $best_sellers_content .= '          <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'products_id=' . $best_sellers['products_id']) . '" class="btn btn-default" role="button">' . SMALL_IMAGE_BUTTON_VIEW . '</a>';
      $best_sellers_content .= '          <a href="' . tep_href_link($PHP_SELF, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $best_sellers['products_id']) . '" class="btn btn-success" role="button">' . SMALL_IMAGE_BUTTON_BUY . '</a>';
      $best_sellers_content .= '        </div>';
      $best_sellers_content .= '      </div>';
      $best_sellers_content .= '    </div>';
      $best_sellers_content .= '  </div>';
      $best_sellers_content .= '</div>';
    }
?>

  <h3><?php echo sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')); ?></h3>

  <div class="row">
    <?php echo $best_sellers_content; ?>
  </div>

<?php
  }
?>
Link to comment
Share on other sites

Hi Ashley;

 

Thanks for the reply and for looking into this :)

 

I tried out your code and it was close but the listings are not arranged left to right as with the stock home page (New Products for September). I thought it would be easier (like, just modify the SQL query) and so I tried that. 

 

I changed order by p.products_date_added to order by p.products_ordered and it worked like a top!

 

The only thing that would be nice to change would be "New Products for September" to something like Most Popular Items. This turned out to be here;

 

includes\languages\english\index.php

define('TABLE_HEADING_NEW_PRODUCTS', 'New Products For %s');

 

I just changed New Products For %s to Popular Purchases and away we go :)

Best & Thanks;
Marvin
----------------------
osCommerce 2.3.3.4 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...