Product Quantity in Magento

For one of my project I needed to display the total quantities ordered in Products lifetime in product view page.

Here is the code

	    
	$product_id = 1; // the id of the product for which the quantities is required	
	$current_storeid = Mage::app()->getStore()->getId();//get current store id, used for filtering the collection
	$productCollection = Mage::getResourceModel('reports/product_collection')
	->addOrderedQty()            
	->addAttributeToSelect(array('name'))
	->addAttributeToFilter('entity_id',array('eq', $product_id))            
	->setStoreId($current_storeid)
	->addStoreFilter($current_storeid)
	->setOrder('ordered_qty');   

        foreach ($productCollection as $_product):
		echo 'Product Name: '.$_product->getName().' Quantities Ordered: '.intval($_product->getOrderedQty()).'<br/>';
	endforeach;
        //end

Hope this is helpful.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top