Assign('view_type','Coming Soon'); else if ($view_type=="top-sellers") $SMARTY->Assign('view_type','Top Sellers'); else $type_sql=" AND p.date_available <= '".DATE_NOW."'"; $cid=$_GET['cid']; // GET CATEGORY INFORMATION $sql="SELECT * FROM categories WHERE alias='$cid' AND active='y'"; $RES=$DB->Qry($sql); if ($RES->GetNumRows()) { $category_info=$RES->GetARow(); $SMARTY->Assign('category_info',$category_info); // INITIALISE PAGINATION if ($_GET['pg'] > 0) $current_page=$_GET['pg']; else $current_page=1; if (!$results_per_page=$category_info['results_per_page']) $results_per_page=10; $result_start = ($current_page*$results_per_page)-$results_per_page; // GET RECURSIVE CATEGORIES IF OPTION IS SET if ($category_info['recursive_listing']=='y') { $recursive_cats=get_child_categories($category_info['id']); $recursive_cats[]=$category_info['id']; $recursive_cats_string=implode(",",$recursive_cats); } else $recursive_cats_string=$category_info['id']; // CALCULATE SORT METHOD if ($_POST['sort']) $_SESSION['sort']=$_POST['sort']; if ($_SESSION['sort']) { $sort=$_SESSION['sort']; $SMARTY->Assign('sort',$sort); if ($sort=="alphabetically") $ORDER_BY="ORDER BY name ASC"; else if ($sort=="bestselling") $ORDER_BY="ORDER BY sales DESC, name ASC"; else if ($sort=="-price") $ORDER_BY="ORDER BY price ASC, name ASC"; else if ($sort=="price") $ORDER_BY="ORDER BY price DESC, name ASC"; else if ($sort=="reviewrank") $ORDER_BY="ORDER BY overall_rating DESC, name ASC"; else if ($sort=="-releasedate") $ORDER_BY="ORDER BY date_available DESC, name ASC"; } else $ORDER_BY="ORDER BY name ASC"; // GET PRODUCT INFORMATION FOR CURRENT CATEGORY // The query only works if the SQL_CALC_FOUND_ROWS uses the distinct(p.alias), this also solves the problem with products // in multiple categories and allows the product to only be displayed once (see other related comments below) if ($view_type=="coming-soon") { $SMARTY->Assign('pre-order-item',true); $sql="SELECT SQL_CALC_FOUND_ROWS distinct(p.alias), p.id, p.* FROM products p, products_to_categories m WHERE m.category_id IN (".$recursive_cats_string.") AND p.id=m.product_id AND p.date_available > '".DATE_TIME_NOW."' AND p.active='y' $ORDER_BY LIMIT $result_start,$results_per_page"; } else if ($view_type=="top-sellers") $sql="SELECT SQL_CALC_FOUND_ROWS distinct(p.alias), p.id, p.* FROM products p, products_to_categories m WHERE m.category_id IN (".$recursive_cats_string.") AND p.id=m.product_id AND p.date_available <= '".DATE_TIME_NOW."' AND p.active='y' ORDER BY sales DESC LIMIT 100"; else $sql="SELECT SQL_CALC_FOUND_ROWS distinct(p.alias), p.id, p.* FROM products p, products_to_categories m WHERE m.category_id IN (".$recursive_cats_string.") AND p.id=m.product_id AND p.date_available <= '".DATE_TIME_NOW."' AND p.active='y' $ORDER_BY LIMIT $result_start,$results_per_page"; $RES=$DB->Qry($sql); if ($RES->GetNumRows()) { $sql="SELECT FOUND_ROWS()"; $GET_TOTAL_ROWS_RES=$DB->Qry($sql); $total_results=$GET_TOTAL_ROWS_RES->GetCell(); $total_pages=ceil($total_results/$results_per_page); // ONLY SHOW ITEMS IF PAGE NUMBER IS WITHIN RANGE if ($current_page >=1 && $current_page <= $total_pages) { $products=array(); $product_start_numeral=(($current_page*$results_per_page)-$results_per_page)+1; $cnt=$product_start_numeral; while ($row=$RES->GetARow()) { $PRODUCT = new Product($row['id']); if ($product_row=$PRODUCT->GetProductInfo()) { // SET THE PRODUCTS CATEGORY NUMERAL $product_row['display_numeral']=$cnt; // FIND OUT IF THIS IS A PRE ORDER ITEM $datediff=datediff($product_row['date_available'],DATE_NOW,'d'); if ($datediff['d'] > 0) $product_row['pre_order_item']=true; // SEE IF THE PRODUCT HAS ATTRIBUTES THAT NEED SELECTING PRIOR TO ADDING TO BASKET $sql="SELECT po.id as option_id,pa.default as att_default, pa.id as att_id, po.id as option_id, pa.price as att_price, pa.price_prefix as att_price_prefix,po.name as options_name,pv.name as values_name FROM products_attributes pa, products_options po, products_options_values pv WHERE pa.options_id=po.id AND pa.values_id=pv.id AND pa.products_id='".$product_row['id']."' ORDER BY pa.sort_order ASC"; $ATTRIB_RES=$DB->Qry($sql); if ($ATTRIB_RES->GetNumRows() > 0) $SMARTY->Assign('product_has_attributes',true); // CALCULATE DELIVERY $product_row['delivery_price']=0; // Only show first occurance multiple instances of same product exists // The distinct(p.alias) in the query means we do not have to do this however //if (!$products[$product_row['alias']]) $products[$product_row['alias']]=$product_row; $products[$product_row['alias']]=$product_row; $cnt++; } } $product_end_numeral=$cnt-1; $SMARTY->Assign('products',$products); } // IF PAGE IS NOT WITHIN RANGE REDIRECT THE USER TO CATEGORY HOME // THIS SHOULD NEVER RUN SINCE THE QUERY WILL RETURN NO RESULTS IF OUTSIDE RANGE else { header ("Location: ".HTTP_SERVER.$category_info['alias']."/1/CategoryHome.html"); exit; } // SET PAGINATION NAVIGATION BUTTONS if ($current_page > 1) $SMARTY->Assign('prev_page',$current_page-1); if ($current_page < $total_pages) $SMARTY->Assign('next_page',$current_page+1); // PAGINATION SMARTY ASSIGNS $SMARTY->Assign('current_page',$current_page); $SMARTY->Assign('total_results',$total_results); $SMARTY->Assign('total_pages',$total_pages); $SMARTY->Assign('product_start_numeral',$product_start_numeral); $SMARTY->Assign('product_end_numeral',$product_end_numeral); } // BUILD THE BREADCRUMB $CATEGORY = new Category($cid); if ($parent_cats=$CATEGORY->aCategoryParentsInfo) { foreach ($parent_cats as $cat) { $cat['link']=HTTP_SERVER.$cat['alias']."/CategoryHome.html"; if ($cat['breadcrumb_name']) $cat['page_name']=$cat['breadcrumb_name']; $bc[]=$cat; } } if ($view_type=="coming-soon") { $cat['link']=""; $cat['page_name']="Coming Soon"; $bc[]=$cat; } else if ($view_type=="top-sellers") { $cat['link']=""; $cat['page_name']="Top Sellers"; $bc[]=$cat; } else { //$cat['link']=""; //$cat['page_name']="Browse All"; //$bc[]=$cat; } $SMARTY->Assign('breadcrumb',$bc); // BUILD META TAGS if ($category_info['meta_title']) $meta_title=$category_info['meta_title']; else $meta_title=$category_info['page_name']; $SMARTY->SetMetaTitle($meta_title); $SMARTY->SetMetaDesc($category_info['meta_desc']); $SMARTY->SetMetaKeyw($category_info['meta_keyw']); $SMARTY->ShowHeader(); $SMARTY->ShowBody('categories.tpl'); $SMARTY->ShowFooter(); } else { header ("Location: ".HTTP_SERVER); exit; } ?>