Jump to content

[SOLVED] How to display number of units sold of particular product


Recommended Posts

Thank you for your reply but I need to show how many units of a particular product have sold.

Not all the products in the catalog.

Instead of 99 item items in stock, I need to show "99 Items have been sold so far"

So I need a count of units sold for a particular product displayed.

Thanks

Link to comment
Share on other sites

You can use following code

at your php file of the page:

$product_sold = Db::getInstance()->executeS('SELECT COUNT(*) as product_sold FROM `'._DB_PREFIX_.'order_detail` where product_id = ' . $product_id);
$smarty->assign('product_sold', $product_sold);




At your tpl file of your page

product_sold: {$product_sold}

Link to comment
Share on other sites

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)

include_once(dirname(__FILE__).'/init.php');



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 attached

(I have tested this code)

32661_9QzdXvIMA7OfpVseeuPv_t

Link to comment
Share on other sites

Thank you for the detailed instructions.

2 issues:

1st issue:

I got the sold count working but it is not outputting the correct number of items sold.

If I order only one then the sold count is increased by one.

If I order quantity 10 of the same product then the sold count is still increased by one and NOT 10

2nd Issue:

I want to put the Sold count in the short description box. Can you advise where to insert the code.

Thank you for all your help

Link to comment
Share on other sites

For Issue 1, I have updated my code above step 1, please redo the changes of step 1, this should fixed the problem.
For Issue 2, It is difficult to give instructions without seeing your source code of the page. I don't know what theme you are using. So it is better you figure it out by yourself. If you still have difficulty, I will take a look for you, please send me the information to access your source code by private message.

Good Luck

Link to comment
Share on other sites

×
×
  • Create New...