Product Quantities Ordered in Magento

I am explaining here the way to display the total quantities ordered in the Product view page.

I have used Magento version

1) Block file

Create a file app/code/local/Mage/Catalog/Block/Product/View/Quantity.php (note the codepool is ‘local’ )

Copy this code in the file and save the file.

class Mage_Catalog_Block_Product_View_Quantity extends Mage_Catalog_Block_Product_View_Abstract
     * Retrieve quantity ordered
     * @return integer
    public function getOrderedQuantity()
    	$product_id = $this->getProduct()->getId();
		$report = Mage::getResourceModel('reports/product_sold_collection')
		return intval($report->getOrderedQty());

2) View File

Create a file app/code/design/frontend/default/default/template/catalog/product/view/quantity.phtml

I have used package – default and theme – default, this can be as per your structure

Copy this code in the file and save the file.

<?php echo 'Qty->'.$_qty = $this->getOrderedQuantity() ?>

3) Layout File

If you dont have ‘local.xml’ file for your theme, create one at app/code/design/frontend/default/default/layout/local.xml

Copy this code in the file and save the file.

<layout version="0.1.0">
<!--  below layout for displaying the quantities ordered in product view page -->
    	<reference name="content">	    	   		
	            <block type="catalog/product_view_quantity" name="catalog.product.quantity" before="-" template="catalog/product/view/quantity.phtml"/>     

And your are done, hope this is helpful

Leave a Reply

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

Scroll to top