Is it possible to display on the product page how many customers purchased a certain item?
How would I achieve this?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityIs it possible to display on the product page how many customers purchased a certain item?
How would I achieve this?
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();
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
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