how to display the Number of sold products in magento?

By default magento does not show sold product count. if we want to show the sold product count in product description page than we need to do custom work . This Magento Blog or Magento Tutorial will tell you how to show sold product in product description page.


<?php 
                             
$items = Mage::getModel('sales/order_item')
    ->getCollection()
    ->addFieldToFilter('product_id', $_product->getId());
if ($_product->isAvailable()){
$ga_cnt = 0;
foreach ($items as $item) {
    $ga_cnt += $item->getQtyOrdered() - $item->getQtyCanceled() - $item->getQtyRefunded();
}
if($ga_cnt > 0){
    echo $ga_cnt.' people have purchased this product';
} else {
    echo 'Be the first to buy this product!';
}
 } else {
    echo 'Product out of stock';

                

?>

1 comment: