<?php
//get shop page's title
$t = $site->pageTitle($s['shop_page']);
$seo_pageTitle = seo_str($t);
//add meta tags to the page if showing a sub category
$meta = $mysql->get_array($mysql->query("seotitle,seokeywords,seodesc", "fs_pages", "ID = ".(int)$s['shop_page']." LIMIT 1"));
$array['page_title'] = (!empty($meta['seotitle'])) ? $meta['seotitle'].' - Best Sellers' : $array['page_title'];
$array['keywords'] = (!empty($meta['seokeywords'])) ? $meta['seokeywords'] : $array['keywords'];
$array['meta_desc'] = (!empty($meta['seodesc'])) ? $meta['seodesc'] : $array['meta_desc'];
//show 40 best selling products
$size = $site->shop_settings('catimage_height,catimage_width');
$products = '<h1>'.$t.'</h1>';
$products .= '<p id="shopCrumbs"><a href="/'.$s['shop_page'].'/'.$seo_pageTitle.'">'.$t.'</a> &gt; <strong>Best sellers</strong></p>';
$products .= '<div id="prodlist">';
$query = $mysql->query("COUNT(fs_shop_cart.ID) AS sales,fs_shop_products.ID,fs_shop_products.name,fs_shop_products.price,fs_shop_products.sale_price,fs_shop_products.thumb_image,fs_shop_products.url_key" ,"fs_shop_cart,fs_shop_products", "fs_shop_cart.temp = 'n' AND fs_shop_products.hide = 'n' AND fs_shop_products.ID = fs_shop_cart.pid GROUP BY fs_shop_cart.pid ORDER BY sales DESC LIMIT 40");
while($data = $mysql->get_array($query))
{
$price = $site->currency_symbol($data['price']);
$shortName = (strlen($data['name']) > 42) ? substr($data['name'], 0, 42).'...' : $data['name'];
if($data['sale_price'] > 0){$price = 'WAS <span class="sale">'.$site->currency_symbol($data['price']).'</span><br /><strong>NOW '.$site->currency_symbol($data['sale_price']).'</strong>';}
$outOfStock = (!$site->in_stock($data['ID'])) ? '<br /><strong>Out of stock</strong>' : '';
$products .= '<table border="0" cellspacing="0" cellpadding="0" width="'.$size['catimage_width'].'">
<tr>
<th><a href="/'.$s['shop_page'].'/'.$seo_pageTitle.'/'.$data['url_key'].'"><img src="/inc/shop/images/clear.gif" alt="'.$data['name'].'" width="'.$size['catimage_width'].'" height="'.$size['catimage_height'].'" border="0" title="'.$data['name'].'" style="background-image: url(/inc/shop/images/'.$data['thumb_image'].');" /></a></th>
</tr>
<tr>
<td><a href="/'.$s['shop_page'].'/'.$seo_pageTitle.'/'.$data['url_key'].'" title="'.$data['name'].'">'.$shortName.'</a> '.$price.$outOfStock.'</td>
</tr>
</table>';
}
$products .= '</div>';
$mainhtml .= stripslashes($products);
//include this add-ons's overwrite css file from the template being used, if there is one
$t = settings('template');
if(file_exists('templates/'.$t['template'].'/addons/shop.css'))
{
$mainhtml = str_replace("</head>", '<link rel="stylesheet" type="text/css" href="/templates/'.$t['template'].'/addons/shop.css" /></head>', $mainhtml);
}
else
{
$mainhtml = str_replace("</head>", '<link rel="stylesheet" type="text/css" href="//www.freesites.com.au/addons/shop.css" /></head>', $mainhtml);
}
//end
?>