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 community
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();
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