View Single Post
  #1  
Old 12-24-2006, 11:39 PM
 
inebriate inebriate is offline
 

eXpert
  
Join Date: May 2006
Posts: 301
 

Default periodic bestseller (weekly/monthly/annually)

warning: this was not tested on a live server, so please backup your xcart sql database just in case...its actually my first time playing with mysql functions but i have a programming background so was able to catch on

note: this will reset your products' sales stats and obviously you must have both the Advanced Statistics and the Bestsellers modules enabled, also products are not considered 'sold' until the order is 'processed'

in modules/Advanced_Statistics/prod_sold.php, look for
Code:
$avail_condition = ""; if ($config["General"]["unlimited_products"] == "N" && $config["General"]["disable_outofstock_products"] == "Y") $avail_condition = " AND $sql_tbl[products].avail>0 ";
and add below it
Code:
#START MOD #****************************************************** # PERIODIC BESTSELLER by david@fabric8d #****************************************************** # d:day # W:week # m:month # Y:year #-------------- # if you want to use a different period, change what is # inside the date() function to one of the values above, # ie: date(m) for monthly. # # also if you want to do a bi- or tri- period, multiply # it in front of the function, ie: 2 * (int)date(W) for # bi-weekly #****************************************************** $dateP = (int)date(W); $dateY = (int)date(Y); $lastupdateP = (int)func_query_first_cell("SELECT period FROM xcart_lastupdate"); if(abs($dateP-$lastupdateP) > 0) { db_query("UPDATE $sql_tbl[products] SET sales_stats=0"); db_query("UPDATE xcart_lastupdate SET period=$dateP"); db_query("UPDATE xcart_lastupdate SET year=$dateY"); } #END MOD

now in the xcart admin section, goto patch/upgrade...in the "SQL query(ies)" textbox, paste one by one each line (or together, i dont know if it will work though)
Code:
CREATE TABLE `xcart_lastupdate` (`period` INT( 2 ) NOT NULL ,`year` INT( 4 ) NOT NULL) UPDATE xcart_lastupdate SET week=51 UPDATE xcart_lastupdate SET year=2006
and apply

also, you may want to update the bestseller label (lbl_bestsellers) to reflect the period

that should be it...it should work for 4.0.x and 4.1.x
__________________
x-cart pro 4.0.18
linux
www.fabric8d.com (currently undergoing construction)
Reply With Quote