1

Is it possible to display on the product page how many customers purchased a certain item?

How would I achieve this?

2

This should work:

$product = Mage::registry('current_product');
$reports = Mage::getResourceModel('reports/product_collection')
    ->addOrderedQty()
    ->addIdFilter($product->getId())
    ->setOrder('ordered_qty', Zend_Db_Select::SQL_DESC);
$reports->getSelect()->limit(1);

echo $reports->getFirstItem()->getOrderedQty();
  • Thanx..but it shows me in floating value...eg. 3.0000 , how could i say that this much people buy this item. actually, i want to display in frontend that, this many cusomers buy this products, thats it. – Sushant Thorat Jul 1 '17 at 10:22
  • 1
    echo 'Item has been sold ' . (int) $reports->getFirstItem()->getOrderedQty() . 'times.'; Note: this is just the number of total order count. Not for unique customers. – sv3n Jul 1 '17 at 10:24
  • Customer count answered in your other question: magento.stackexchange.com/questions/181608/… – sv3n Jul 1 '17 at 10:49
  • that is good. if i want tot also get all this total order item grand total amount. like 5 product order and it's price is $10 per product then total amount should be $50. – Sarfaraj Sipai Oct 1 '18 at 7:22
0

You can use these code at these location by padding product id in query

File Path: app/design/frontend/rwd/default/template/catalog/product/view.phtml

<?php 
echo $productId = $_product->getId();
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$sql = "SELECT count(*) FROM `sales_flat_order_item` WHERE `product_id` = $productId";
$rows = $connection->fetchOne($sql);
echo $rows;
?>

For more clarity take a look of below screen-shot

https://www.awesomescreenshot.com/image/2626598/3811ea202d982ba52d13fd54b02dd57a

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.