View Single Post
  #1  
Old 01-31-2007, 02:27 PM
 
lachild lachild is offline
 

Advanced Member
  
Join Date: May 2006
Posts: 92
 

Default Best Sellers WITH OUT Advanced Statistics

Heres a quick mod to enable Best Sellers without slowing down your site by turning on Advanced Statistics. Instead it uses the power of MySQL to do the research for you.

This script will also add how many times this product has been purchased for the last thirty days as well. You can of course simply remove this feature in the new template file if you don't want this displayed.

Please note this has only been tested on version 4.1

To begin create a new file "/modules/Bestsellers/newbestsellers.php"

Paste in the following code into the new file:
Code:
<?php ///////////////////////// /// Bestsellers Mod /// /// By: Westin Shafer /// ///////////////////////// //Set Dates $today = mktime(0, 0, 0, date("m"), date("d"), date("Y")); $lastmonth = mktime(0, 0, 0, date("m")-1, date("d"), date("Y")); // Get Best Sellers for last 30 days // We get 20 just in case there is a problem with one of the entries. // Get Best Sellers for last 30 days $getbestSellers = func_query("SELECT xcart_order_details.productid, COUNT( * ) AS count FROM xcart_order_details LEFT JOIN xcart_orders ON ( xcart_order_details.orderid = xcart_orders.orderid ) WHERE xcart_order_details.productid NOT LIKE '0' AND xcart_orders.status NOT LIKE 'F' AND xcart_orders.status NOT LIKE 'I' AND xcart_orders.status NOT LIKE 'D' AND xcart_orders.status NOT LIKE 'X' AND xcart_orders.date BETWEEN '$lastmonth' AND '$today' GROUP BY xcart_order_details.productid ORDER BY count DESC LIMIT 20 "); /// Failsafe in case products have been deleted $count = 0; foreach ($getbestSellers as $value){ $bestsellers["$value[productid]"]['title'] = func_query_first_cell("SELECT product FROM xcart_products WHERE productid LIKE $value[productid]"); $bestsellers["$value[productid]"]['units'] = $value['count']; if ($bestsellers["$value[productid]"]['title'] != '') $count++; else unset($bestsellers["$value[productid]"]); if ($count == 10) break; } $smarty->assign("bestsellers", $bestsellers); ?>

Next create a new file "/skin1/modules/Bestsellers/newbestsellers.tpl"

Paste in the following code and customize to your liking:
Code:
{capture name=bestsellers} <table width="100%"> <tr> <td align="center">Name</td> <td align="center">Units Sold</td> </tr> {foreach from=$bestsellers item=best key=key} <tr> <td><a href="product.php?productid={$key}">{$best.title}</a></td> <td><a href="product.php?productid={$key}">{$best.units}</a></td> </tr> {/foreach} </table> {/capture} {include file="dialog.tpl" title=$lng.lbl_bestsellers content=$smarty.capture.bestsellers extra='width="100%"'}

Next find the following in home.php
Code:
if ($active_modules["Bestsellers"]) include $xcart_dir."/modules/Bestsellers/bestsellers.php";

Replace with:
Code:
require $xcart_dir."/modules/Bestsellers/newbestsellers.php";

Finally add the following anywhere on your homepage where you want these displayed.
Code:
{include file="modules/Bestsellers/newbestsellers.tpl"}

Enjoy

Edit: Changed MySQL call to exclude failed transactions.
__________________
Westin Shafer
Come Together Technologies
http://www.ComeTogetherTechnologies.com
Reply With Quote