I'm trying (but failing) to create 'Best Sellers' and 'New Releases' pages for my website. I'm using WP-Ecommerce 3.8.4 with WP 3.1.3 and I've gotten close but can't seem to get it right. Any help on this would be greatly appreciated...
I've added the following code to wp-ecommerce>wpsc-includes>product-template.php (original code from here):
//Popular products function
function popular_products ( $atts ) {
//Expose the Db to the function
global $wpdb;
//Get the results
$pp = $wpdb -> get_results ( "SELECT prodid, SUM(quantity) FROM {$wpdb->prefix}wpsc_cart_contents GROUP BY prodid ORDER BY quantity DESC LIMIT {$atts['limit']}", ARRAY_A);
//Loop through the results
foreach ( $pp as $item ) {
//Output it
?>
<img alt="<?php echo wpsc_the_product_title ( null, null, $item['prodid'] )?>" src="<?php echo wpsc_the_product_thumbnail ( null, null, $item['prodid'] )?>" />
<?php echo wpsc_the_product_title ( $item['prodid'] )?>
<?php
}
}
add_shortcode ( 'dm_popular', popular_products );
//END OF POPULAR PRODUCTS
I've then added [dm_popular limit=5] to the best sellers page (http://www.iconiccanvasart.co.uk/best-sellers) but as you can see it's not quite working properly:
- one product can appear multiple times if it's been ordered in different variations.
- it isn't retrieving the Products title properly (all are outputted as 'Best Sellers').
- Ditto for the image Alt tags.
- I've not added a URL to the products yet as not sure how to at the moment.
Once I've this working I'm hoping to alter slightly and have a 'New Releases' page based on a similar query (so any help on this may help to killing two birds with one stone).
Any help would be greatly appreciated.
ChainsawDR
EDIT: I've since managed to get this all working bar the price and product text - final code can be viewed here: http://getshopped.org/forums/topic/bestselling-products/