Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Best Sellers WITH OUT Advanced Statistics

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #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

The following 3 users thank lachild for this useful post:
am2003 (11-09-2010), D Brugge (04-02-2010), lash (11-05-2009)
  #2  
Old 02-22-2007, 03:04 PM
 
stevekem stevekem is offline
 

Senior Member
  
Join Date: Dec 2006
Posts: 111
 

Default Re: Best Sellers WITH OUT Advanced Statistics

Hello,

I tried the code and it does work for me on 4.1.3 on category's and welcome page, but the new bestsellers menu that I copied your code into seems to disappear on the product details page. Do you happen to know why? Thanks!
__________________
X-Cart Gold v4.4.1
Reply With Quote
  #3  
Old 02-25-2007, 08:20 PM
 
lachild lachild is offline
 

Advanced Member
  
Join Date: May 2006
Posts: 92
 

Default Re: Best Sellers WITH OUT Advanced Statistics

Sorry for the long delay. I actually didn't notice the question the first time through..

We only use best sellers on the home page but I did find the code your looking for to fix this on the products page.

locate this in product.php:
Code:
if ($active_modules["Bestsellers"]) include $xcart_dir."/modules/Bestsellers/bestsellers.php";

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

Also if this is being displayed on the shopping cart then you will need to edit cart.php and add...
Code:
require $xcart_dir."/modules/Bestsellers/newbestsellers.php";
...somewhere to the end of the file before func_display (I believe).
__________________
Westin Shafer
Come Together Technologies
http://www.ComeTogetherTechnologies.com
Reply With Quote
  #4  
Old 03-01-2007, 06:01 PM
 
stevekem stevekem is offline
 

Senior Member
  
Join Date: Dec 2006
Posts: 111
 

Default Re: Best Sellers WITH OUT Advanced Statistics

Thanks for letting me know. I appreciate it.

- Steve
__________________
X-Cart Gold v4.4.1
Reply With Quote
  #5  
Old 08-27-2008, 09:49 AM
 
GMADMIN GMADMIN is offline
 

Member
  
Join Date: Sep 2006
Posts: 12
 

Default Re: Best Sellers WITH OUT Advanced Statistics

Can you tell me: does this present the number of orders with a certain item, or the actual number of units sold in the period? Thanks.
__________________
-GMADMIN-
Xcart 4.0.18
Reply With Quote
  #6  
Old 10-30-2008, 11:46 AM
 
starwest starwest is offline
 

eXpert
  
Join Date: Sep 2006
Posts: 268
 

Default Re: Best Sellers WITH OUT Advanced Statistics

Can anyone who has tried this mod comment on the performance versus using the stock best sellers module (with advanced statistics)?

Thanks!
__________________
X-Cart Gold v4.1.10 [unix]
AOM, Special Offers, CDSEO Pro, Remember Anon Carts, Back-In-Stock Notifications, MM3, Feed Manager
Reply With Quote
  #7  
Old 12-10-2008, 10:18 AM
 
Jerrad Jerrad is offline
 

X-Adept
  
Join Date: Nov 2004
Location: The Netherlands
Posts: 484
 

Default Re: Best Sellers WITH OUT Advanced Statistics

Does anybody know how to include thumbnails with the bestsellers?

Thanks!
__________________
X-Cart 4.0.12
Heavy modified with paid, free and forum mods.
PHP 5.2.5 | MYSQL 5.0.51a
Reply With Quote
  #8  
Old 05-13-2009, 08:04 AM
 
erik erik is offline
 

Advanced Member
  
Join Date: Nov 2008
Posts: 45
 

Default Re: Best Sellers WITH OUT Advanced Statistics

Can this script be modified to exclude categories from best sellers?
__________________
/erik daugbjerg/
X-Cart 4.6.6
Reply With Quote
  #9  
Old 11-05-2009, 06:42 AM
 
lash lash is offline
 

Senior Member
  
Join Date: Oct 2006
Posts: 138
 

Default Re: Best Sellers WITH OUT Advanced Statistics

It works fine in 4.1.9 and doesn't slow down the site since you don't need to turn on the advanced statistics. The difference compared the default bestsellers is that this one just show the main bestsellers. X-cart can show bestsellers in different categories. If I go to category B it will show bestseller from that category. This one won't do that and perhaps you don't want it to either...
__________________
4.1.9
www.lash.se
Reply With Quote
  #10  
Old 11-05-2009, 09:02 AM
 
starwest starwest is offline
 

eXpert
  
Join Date: Sep 2006
Posts: 268
 

Default Re: Best Sellers WITH OUT Advanced Statistics

Quote:
Originally Posted by lash
It works fine in 4.1.9 and doesn't slow down the site since you don't need to turn on the advanced statistics. The difference compared the default bestsellers is that this one just show the main bestsellers. X-cart can show bestsellers in different categories. If I go to category B it will show bestseller from that category. This one won't do that and perhaps you don't want it to either...


That sums it up pretty well. Good performance, especially versus the default functionality that uses advanced stats, but not much in the way of features. It would be nice to see a mod that provided similar performance and the ability to configure additional features, such as choosing to show best-sellers by category.
__________________
X-Cart Gold v4.1.10 [unix]
AOM, Special Offers, CDSEO Pro, Remember Anon Carts, Back-In-Stock Notifications, MM3, Feed Manager
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:15 AM.

   

 
X-Cart forums © 2001-2020