We are creating a bestseller block and use the code below. With the code below we get a nice list of products. The only problem is that many of these products are either very old - and hardly ever sold. It almost seems that, either:

a. reports/product_collection contains very old, not actual data

b. the results are sorted the wrong way around (doesn't seem so)

c. something else? UPDATE: it seems the output is SIMPLE producs only - and we sell configurable products in our fashion store. This is why only some products are showing: these are the only simple products we have.

question: How can we get the 'real' bestsellers in the code below?

help appreciated (Magento

public function getCollection()
    $storeId = Mage::app()->getStore()->getId();
    $collection = Mage::getResourceModel('reports/product_collection')
        ->setOrder('ordered_qty', 'desc');

    if (Mage::helper('catalog/product_flat')->isEnabled()) {
            ->joinInner(array('e2' => 'catalog_product_flat_' . $storeId), 'e2.entity_id = e.entity_id');
    } else {
            ->addAttributeToSelect(array('name', 'price', 'small_image'));


    $_limit = (int)$this->getLimit() ?: 3;
    $collection->setPage(1, $_limit);
    return $collection;

1 Answer 1


Don't know why you are getting this old products. But you might try this solution is working nicely for me:

public function getBestsellerProducts()
    $storeId = (int) Mage::app()->getStore()->getId();

    // Date
    $date = new Zend_Date();
    $toDate = $date->setDay(1)->getDate()->get('Y-MM-dd');
    $fromDate = $date->subMonth(1)->getDate()->get('Y-MM-dd');

    $collection = Mage::getResourceModel('catalog/product_collection')

            array('aggregation' => $collection->getResource()->getTable('sales/bestsellers_aggregated_monthly')),
            "e.entity_id = aggregation.product_id AND aggregation.store_id={$storeId} AND aggregation.period BETWEEN '{$fromDate}' AND '{$toDate}'",
            array('SUM(aggregation.qty_ordered) AS sold_quantity')
        ->order(array('sold_quantity DESC', 'e.created_at'));


    return $collection;

Full article at: http://inchoo.net/magento/bestseller-products-in-magento/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.