There is always a need to understand which products are selling best within Magento. Yet there seems to be little information to retrieve the total quantity of products purchased from your date? You can use the simple piece of code below to return all products along with their purchased quantity.

This will return an instance of Mage_Sales_Model_Resource_Order_Item_Collection which you’re then able to iterate through and return each products purchased quantity. Your Varien_Object will contain both the sku and a field called purchased which relates to the total purchased amount.

If you’re wanting to only get the purchased quantity for a single product you can do this using the following code.

Replacing SKU with your desired SKU. This will return a singular object rather than a collection.

You can also get the amount of purchases for an item in a time period, within the same query. I used this to build a “What’s Trending” facility using Elasticsearch.

This assigns the quantity ordered in the last day to purchased_day. Along with the purchased in total field.

Dave Macaulay
Dave Macaulay
I'm an enthusiastic, slightly eccentric Magento developer who bores with the idea of another basic brief.