Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Best Sellers page


Guest

Recommended Posts

Hi

 

I was just wondering how to make a best sellers page

 

I have made a new php page for it and I thought by copying the coding from the bm_best_sellers.php file from includes/modules/boxes it would work but have no products showing and one should be displayed

 

Any ideas

 

Kind regards

 

Ian

Link to comment
Share on other sites

Hi Bob

 

The coding I got is below

 

<?php
/*
 $Id$
 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com
 Copyright (c) 2010 osCommerce
 Released under the GNU General Public License
*/
 require('includes/application_top.php');
 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_BESTSELLERS);
 $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_BESTSELLERS));
 require(DIR_WS_INCLUDES . 'template_top.php');
?>
<h1><?php echo HEADING_TITLE; ?></h1>
<div class="contentContainer">
 <div class="contentText">
   <?php echo TEXT_INFORMATION; ?>
 </div>

 <?php
 class bm_best_sellers {
   var $code = 'bm_best_sellers';
   var $group = 'boxes';
   var $title;
   var $description;
   var $sort_order;
   var $enabled = false;
   function bm_best_sellers() {
  $this->title = MODULE_BOXES_BEST_SELLERS_TITLE;
  $this->description = MODULE_BOXES_BEST_SELLERS_DESCRIPTION;
  if ( defined('MODULE_BOXES_BEST_SELLERS_STATUS') ) {
    $this->sort_order = MODULE_BOXES_BEST_SELLERS_SORT_ORDER;
    $this->enabled = (MODULE_BOXES_BEST_SELLERS_STATUS == 'True');
    $this->group = ((MODULE_BOXES_BEST_SELLERS_CONTENT_PLACEMENT == 'Left Column') ? 'boxes_column_left' : 'boxes_column_right');
  }
   }
   function execute() {
  global $HTTP_GET_VARS, $current_category_id, $languages_id, $oscTemplate;
  if (!isset($HTTP_GET_VARS['products_id'])) {
    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);
    }
    if (tep_db_num_rows($best_sellers_query) >= MIN_DISPLAY_BESTSELLERS) {
	  $bestsellers_list = '<ol style="margin: 0; padding-left: 25px;">';
	  while ($best_sellers = tep_db_fetch_array($best_sellers_query)) {
	    $bestsellers_list .= '<li><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $best_sellers['products_id']) . '">' . $best_sellers['products_name'] . '</a></li>';
	  }
	  $bestsellers_list .= '</ol>';
	  $data = '<div class="ui-widget infoBoxContainer">' .
			  '  <div class="ui-widget-header infoBoxHeading">' . MODULE_BOXES_BEST_SELLERS_BOX_TITLE . '</div>' .
			  '  <div class="ui-widget-content infoBoxContents">' . $bestsellers_list . '</div>' .
			  '</div>';
	  $oscTemplate->addBlock($data, $this->group);
    }
  }
   }
   function isEnabled() {
  return $this->enabled;
   }
   function check() {
  return defined('MODULE_BOXES_BEST_SELLERS_STATUS');
   }
   function install() {
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Best Sellers Module', 'MODULE_BOXES_BEST_SELLERS_STATUS', 'True', 'Do you want to add the module to your shop?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Content Placement', 'MODULE_BOXES_BEST_SELLERS_CONTENT_PLACEMENT', 'Right Column', 'Should the module be loaded in the left or right column?', '6', '1', 'tep_cfg_select_option(array(\'Left Column\', \'Right Column\'), ', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_BOXES_BEST_SELLERS_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
   }
   function remove() {
  tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
   }
   function keys() {
  return array('MODULE_BOXES_BEST_SELLERS_STATUS', 'MODULE_BOXES_BEST_SELLERS_CONTENT_PLACEMENT', 'MODULE_BOXES_BEST_SELLERS_SORT_ORDER');
   }
 }
?>
 <div class="buttonSet">
   <span class="buttonAction"><?php echo tep_draw_button(IMAGE_BUTTON_HOME, 'triangle-1-e', tep_href_link(FILENAME_DEFAULT)); ?></span>
 </div>
</div>
<?php
 require(DIR_WS_INCLUDES . 'template_bottom.php');
 require(DIR_WS_INCLUDES . 'application_bottom.php');
?>

Link to comment
Share on other sites

Holy crap, no wonder that ain't working. You can't just take box code and place it into a page like that - I even cover how to use box code (outside boxes) in the tutorial (which you do have!).

 

Take a copy of products_new.php and change the order by to p.products_ordered DESC

Link to comment
Share on other sites

Here's one ripped off from specials.php...

<?php
/*
 $Id$
 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com
 Copyright (c) 2010 osCommerce
 Released under the GNU General Public License
 This was the specials page but ripped off by BT to make a quick and dirty best_sellers.php
*/
 require('includes/application_top.php');
 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SPECIALS);//<--- need to make up a language file
 $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_SPECIALS));
 require(DIR_WS_INCLUDES . 'template_top.php');
?>
<h1><?php echo HEADING_TITLE; ?></h1>
<div class="contentContainer">
 <div class="contentText">
<?php //BT comment out orignal code
// $specials_query_raw = "select p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and s.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1' order by s.specials_date_added DESC";

//now here's the code from bm_best sellers
	 //  $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);
//so  amalgamte them change that to
$specials_query_raw = "select p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image 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";   
//from now on $specials_xx should be changed to $bestsellers buy hey, it's Friday

 $specials_split = new splitPageResults($specials_query_raw, MAX_DISPLAY_SPECIAL_PRODUCTS);
 if (($specials_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3'))) {
?>
   <div>
  <span style="float: right;"><?php echo TEXT_RESULT_PAGE . ' ' . $specials_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></span>
  <span><?php echo $specials_split->display_count(TEXT_DISPLAY_NUMBER_OF_SPECIALS); ?></span>
   </div>
   <br />
<?php
 }
?>
   <table border="0" width="100%" cellspacing="0" cellpadding="2">
  <tr>
<?php
   $row = 0;
   $specials_query = tep_db_query($specials_split->sql_query);
   while ($specials = tep_db_fetch_array($specials_query)) {
  $row++;
  echo '	    <td align="center" width="33%"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $specials['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $specials['products_image'], $specials['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br /><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $specials['products_id']) . '">' . $specials['products_name'] . '</a><br />' . $currencies->display_price($specials['products_price'], tep_get_tax_rate($specials['products_tax_class_id'])) . '</span></td>' . "\n";
  if ((($row / 3) == floor($row / 3))) {
?>
  </tr>
  <tr>
<?php
  }
   }
?>
  </tr>
   </table>
<?php
 if (($specials_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3'))) {
?>
   <br />
   <div>
  <span style="float: right;"><?php echo TEXT_RESULT_PAGE . ' ' . $specials_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></span>
  <span><?php echo $specials_split->display_count(TEXT_DISPLAY_NUMBER_OF_SPECIALS); ?></span>
   </div>
<?php
 }
?>
 </div>
</div>
<?php
 require(DIR_WS_INCLUDES . 'template_bottom.php');
 require(DIR_WS_INCLUDES . 'application_bottom.php');
?>

Link to comment
Share on other sites

Hi Burt

 

Im such a idiot if I knew I had the tutorial all along, what book is it in and will have a look now and in the mean time will take a copy of the products_new.php and change the order by to p.products_ordered DESC

Link to comment
Share on other sites

Hi Ian,

 

Take x 1 x hour or x 2 break and read the book

 

I said it will save hours of running in the dark.

 

Regards

 

Joli

To improve is to change; to be perfect is to change often.

 

Link to comment
Share on other sites

You need to change all the products_new calls to best_sellers or what ever you have called them. I did something similar to a page as my store offered free products, and I wanted a page that showed just the free products.

 

There was also an addon for best sellers for an earlier version of oscommerce, so that could have been modified also. I hope you are releasing your newer version for all to use in the addons area.

REMEMBER BACKUP, BACKUP AND BACKUP

Link to comment
Share on other sites

Im up for releasing it as a add on as want to give something back for all the times people have helped me

 

How do I go about making it a add on

Link to comment
Share on other sites

Is it ok to ask someone to check my coding to make sure it is all ok before I release it as a add on

 

I did notice though the footer text is not being displayed on the bestsellers.php page

 

The coding is below

 

<?php
/*
 $Id$
 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com
 Copyright (c) 2010 osCommerce
 Released under the GNU General Public License
*/
 require('includes/application_top.php');
 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_BESTSELLERS);
 $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_BESTSELLERS));
 require(DIR_WS_INCLUDES . 'template_top.php');
?>
<h1><?php echo HEADING_TITLE; ?></h1>
<div class="contentContainer">
 <div class="contentText">
<?php
   $best_sellers_query = tep_db_query("select p.products_id, pd.products_name, p.products_image, p.products_price, 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 = '" . $languages_id . "' order by p.products_ordered DESC, pd.products_name limit " . MAX_DISPLAY_NEW_PRODUCTS);
 $row = 0;
 $col = 0;
 while ($best_sellers = tep_db_fetch_array($best_sellers_query)) {
   $best_sellers['products_name'] = tep_get_products_name($best_sellers['products_id']);
   $info_box_contents[$row][$col] = array('align' => 'center',
									   'params' => 'class="smallText bestsellers" width="33%" valign="top"',
									   'text' => '<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><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $best_sellers['products_id']) . '">' . $best_sellers['products_name'] . '</a><br>' . $currencies->display_price($best_sellers['products_price'], tep_get_tax_rate($best_sellers['products_tax_class_id'])));
   $col ++;
   if ($col > 2) {
  $col = 0;
  $row ++;
   }
 }

 new contentBox($info_box_contents);
?>
<div>
  <span style="float: right;"><?php echo TEXT_RESULT_PAGE . ' ' . $products_new_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></span>
  <span><?php echo $products_new_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS_NEW); ?></span>
   </div>
   <br />
   <div>
  <?php echo TEXT_NO_NEW_PRODUCTS; ?>
   </div>
 </div>
</div>
<?php
 require(DIR_WS_INCLUDES . 'template_bottom.php');
 require(DIR_WS_INCLUDES . 'application_bottom.php');
?>

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...