| #| All rights reserved. | #+-----------------------------------------------------------------------------+ # # $Id: newproducts.php,v 2.0.1 2007/07/07 12:30:00 jfc Exp $ # define('OFFERS_DONT_SHOW_NEW',1); require "./auth.php"; # This sets the default number of days to search for new products $default_days = 30; # WCM - CDSEO Links # include WebsiteCM CDSEO if it exists if (file_exists($xcart_dir."/modules/cdseolinks/cdseo_cat.php")) { include $xcart_dir."/modules/cdseolinks/cdseo_cat.php"; } require $xcart_dir."/include/categories.php"; if ($active_modules["Manufacturers"]) include $xcart_dir."/modules/Manufacturers/customer_manufacturers.php"; if ($active_modules["Bestsellers"]) include $xcart_dir."/modules/Bestsellers/bestsellers.php"; # Load the search functions x_load('product'); # Debugging help # function print_debug($aString) { # comment out to stop debug info # print $aString; return ; } # this could be set as a config option if (!$days || $days == 0) {$days = $default_days;} # default sorting if needed. This could be a config option. if (!$sortby || $sortby == "") { $sortby = "add_date"; } # This array is used to determine the from/to date range # in the WHERE clause. It is also used for the labels # for the range. $newproducts_dayrange = array( 1 => func_get_langvar_by_name("lbl_newproducts_24hrs"), 3 => func_get_langvar_by_name("lbl_newproducts_3days"), 7 => func_get_langvar_by_name("lbl_newproducts_7days"), 30 => func_get_langvar_by_name("lbl_newproducts_30days") ); # This array is used to determine the order by clause and labels # used for sorting $sort_fields = array( "add_date" => func_get_langvar_by_name("lbl_newproducts_adddate"), "productcode" => func_get_langvar_by_name("lbl_newproducts_sku"), "product" => func_get_langvar_by_name("lbl_newproducts_product"), "price" => func_get_langvar_by_name("lbl_newproducts_price") ); # set date ranges $date_range = 86400 * (integer)$days; // 60(sec) * 60(min) * 24(hrs) * $days in unix time $now_time = time(); $from_time = $now_time - $date_range; # Don't show new products that are not available. $avail_condition = " AND $sql_tbl[products].avail > 0 "; $query = "$avail_condition AND add_date > $from_time AND add_date < $now_time "; # determine how many products fit the query criteria. # limit the maximum number of pages in the query ** optimization ** $max_ret_pages = $config["Appearance"]["products_per_page"] * $config["Appearance"]["max_nav_pages"]; print_debug("MAX_RET_PAGES: $max_ret_pages
"); # # SORT DIRECTION # if ($sortby == "price") { $sortorder = "$sql_tbl[pricing].$sortby"; } else { $sortorder = "$sql_tbl[products].$sortby"; } if (!sortdirection || ($sortdirection == "") || ($sortdirection == "0")) { $sort_dir = "desc"; $sortdirection = "0"; } else { $sort_dir = "asc"; $sortdirection = "1"; } print_debug("QUERY: $query
"); $temp_products = func_search_products($query, @$user_account["membershipid"], $orderby="$sortorder $sort_dir", $limit="$max_ret_pages"); #$temp_products = func_query("select xcart_products.*,xcart_quick_flags.* from xcart_products LEFT JOIN xcart_quick_flags ON xcart_quick_flags.productid = xcart_products.productid WHERE forsale = 'Y' ORDER BY add_date ASC LIMIT 4"); # if we don't get anything back.. create an empty array if (is_array($temp_products)){ # get the total items new products. $total_items = count($temp_products); } else { $total_items = 0; } print_debug("TOTAL ITEMS: $total_items
"); if ($total_items > 0) { # # Prepare the page navigation # if(!isset($objects_per_page)) { if ($current_area == "C" || $current_area == "B") $objects_per_page = $config["Appearance"]["products_per_page"]; else $objects_per_page = $config["Appearance"]["products_per_page_admin"]; } $total_nav_pages = ceil($total_items/$objects_per_page)+1; print_debug("Object per PAGE: $objects_per_page
"); print_debug("TOTAL NAV PAGES: $total_nav_pages
"); # calculate the upper and lower LIMIT for the SQL statement if (($page == 1) || $page == "") { $lowerLimit = 0; } else { $lowerLimit = (($page - 1) * $objects_per_page); } $upperLimit = ($lowerLimit + $objects_per_page); } # if we have items to show.. go get them.. if not it will default to empty string "". if ($total_items > 0) { # get the product list that is limited to the page we need to display. print_debug("temp_products count: " . count($temp_products) . "
"); print_debug("lowerLimit: $lowerLimit upperLimit: $upperLimit
"); $newproducts = array_slice($temp_products, $lowerLimit, ($upperLimit - $lowerLimit)); print_debug("newproducts count: " . count($newproducts) . "
"); } else { $newproducts = array(); } include $xcart_dir."/include/navigation.php"; # flag set that is used in home_main.tpl $smarty->assign("main","newproducts"); $smarty->assign("newproducts_dayrange", $newproducts_dayrange); $smarty->assign("sort_fields", $sort_fields); $smarty->assign("days",$days); $smarty->assign("sortby",$sortby); $smarty->assign("sortdirection",$sortdirection); # give the product array to smarty to make it available sitewide. $smarty->assign("products",$newproducts); $smarty->assign("first_item", $first_page+1); $smarty->assign("last_item", min($first_page+$objects_per_page, $total_items)); $smarty->assign("total_items",$total_items); $smarty->assign("navigation_script","newproducts.php?days=$days&sortby=$sortby&sortdirection=$sort_direction"); # create the location bar xxx :: New Products $location[] = array(func_get_langvar_by_name("lbl_newproducts"), "newproducts.php"); $smarty->assign("location",$location); # This function will start the display of the .tpl's func_display("customer/home.tpl",$smarty); ?>