Wednesday, November 3, 2010

PrestaShop Tips - How to display sold count of product

Most online store owners would like to display sold count (number of units sold) of product to indicate the popularity of a product. At PrestaShop, by default, there is no this function or feature, but you can add this by yourself if you know a little bit PHP coding.

It depends where you want this to show up. Here is the code for displaying sold count on product detail page.

1. at product.php file, look for following line (on the top of the file)


add following code right AFTER above line

$product_sold = Db::getInstance()->getRow('SELECT SUM(product_quantity) as total FROM `'._DB_PREFIX_.'order_detail` where product_id = ' . $_GET['id_product']);
$smarty->assign('product_sold', $product_sold['total']);

2. At . /themes/yourthemes/product.tpl file, look for following line

<p class="price">

add following line right AFTER above line

{l s='Sold Count:'}{$product_sold} <br /><br />

And the result will look like below.

No comments: