Magento 1 – How to Display Quantity Order for Product on Product Page

magento-1ordersproductreports

Trying to get this to work, it is not return anything 🙁

 $product = Mage::getResourceModel('reports/product_collection')
 ->addOrderedQty()
 ->addAttributeToFilter('sku', $_product->getSku());
 echo 'Already Bought '.(int)$product->ordered_qty; ?>

Best Answer

As part of the function addOrderedQty it will only add product information for the simple product types. What you could to is rewrite this function so that it does not add the following to the join conditions.

$adapter->quoteInto('(e.type_id NOT IN (?))', $compositeTypeIds),

Then this will give you the information about all product types. Once you have this information you can simply get the first item and get the ordered_qty.

$product->getFirstItem()->getOrderedQty();
Related Topic