<?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); 
/*
* Best selling Products module for mambo-phpShop
* @version $Id: mod_phpshop_topten.php,v 1.3 2004/11/11 18:33:51 soeren_nb Exp $
* @package Mambo_4.5.1
* @subpackage mambo-phpShop
*
* @copyright (C) John Syben (john@webme.co.nz)
* Conversion to Mambo and the rest:
* 	@copyright (C) 2004 Soeren Eberhardt
*
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* mambo-phpShop is Free Software.
* mambo-phpShop comes with absolute no warranty.
*
* www.mambo-phpshop.net
*----------------------------------------------------------------------
* This code creates a list of the bestselling products
* and displays it wherever you want
*----------------------------------------------------------------------
*/
global $mosConfig_absolute_path, $sess;

/* Load the phpshop main parse code */
require_once( $mosConfig_absolute_path.'/components/com_phpshop/phpshop_parser.php' );

require_once(CLASSPATH.'ps_product.php');
$ps_product = new ps_product;

require_once(CLASSPATH.'ps_product_attribute.php');
$ps_product_attribute = new ps_product_attribute;

require_once(CLASSPATH.'ps_product_category.php');
$ps_product_category = new ps_product_category;

// change the number of items you wanna haved listed via module parameters
$num_topsellers = $params->get ('num_topsellers', 10);

?>

<!--Top 10-->
<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tr>
<td>
	
<?php
$list  = "SELECT distinct #__pshop_product.product_id, #__pshop_product.product_parent_id,#__pshop_product.product_name ";
$list .= "FROM #__pshop_product, #__pshop_product_category_xref, #__pshop_category WHERE ";
$q = "#__pshop_product.product_publish='Y' AND ";
$q .= "#__pshop_product.product_sales>0 ";
$q .= "ORDER BY #__pshop_product.product_sales DESC";
$list .= $q . " LIMIT 0, $num_topsellers "; 
?>

	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="menu">
	<?php
  $db = new ps_DB;
	$db->query($list);
	$tt_item=0;
  $i = 0;
  while ($db->next_record()) {
      if ($i == 0) {
          $sectioncolor = "sectiontableentry2";
          $i += 1;
      }
      else {
          $sectioncolor = "sectiontableentry1";
          $i -= 1;
      } 
      $flypage = $ps_product->get_flypage($db->f("product_id"));
      $tt_item++;
      $pid = $db->f("product_parent_id") ? $db->f("product_parent_id") : $db->f("product_id");
      ?>
    <tr class="<? echo $sectioncolor ?>">
      <td valign="top"><?php printf("%02d", $tt_item); ?>&nbsp;<br /></td>
      <td valign="top">
        <a href="<?php  $sess->purl(URL . "index.php?page=shop.product_details&flypage=$flypage&product_id=" . $pid . "&category_id=" . $db->f("category_id")) ?>">
                      <?php $db->p("product_name"); ?>
                          </a><br />
          </td>
    </tr>
    <?php 
  } ?>
	</table>
</td>
</tr>
</table>
<!--Top 10 End-->
