I'm trying to develop a module to display top 10 bestseller products for each category. (I'll use it on home page for overall top 10 products too)

I have bundle, configurable and simple products in my store. And I would like to list top 10 for category A like this

  1. Product X (simple)
  2. Product Y (configurable - with 3 child products, all childs are invisible on store)
  3. Product Z (bundle)
  4. Product W (simple)...

When I check the reports section, the bestseller products report doesnt list configurable products as a parent product, instead it lists all child products as a seperate sales record. That is acceptable if I would like to see which child products performed better but it is useless at the frontend. I can see the report I need at Reports > Product > Products Ordered section, I've tried to debug its execution to see how it populates the list there. It's using soldAction at the "Mage/Adminhtml/controllers/Report/ProductController.php".

I am currently using the below code for testing, you can see the method I'm using to populate collection on model file. This doesn't list the configurable/bundle products, it just skips them and lists single products only.

  • config.xml

    <?xml version="1.0"?>
  • Model/Top/Overall.php

    class Fit_Statistics_Model_Top_Overall extends Mage_Core_Model_Abstract
        public function getBestsellersOverall()
            $storeId = Mage::app()->getStore()->getId();
            $products = Mage::getResourceModel('reports/product_collection')->addOrderedQty()->addAttributeToSelect(array('name', 'price', 'small_image')
                            ->setStoreId($storeId)->addStoreFilter($storeId)->setOrder('ordered_qty', 'desc'); //best sellers on top
            return $products;
  • Block/Top/Overall.php

    class Fit_Statistics_Block_Top_Overall extends Mage_Core_Block_Template {
        public function getBestsellerProducts()
            $arr_products = array();
            $products     = Mage::getModel("fit_statistics/top_overall")->getBestsellersOverall();
            foreach($products as $product) {
                $arr_products[] = array('id' => $product->getId(), 'name' => $product->getName(), 'url' => $product->getProductUrl(),);
            return $arr_products;
  • frontend/base/default/template/fit_statistics/top/overall.phtml

    $products = $this->getBestsellerProducts();
    <div id="product_list">
        <h1>Bestseller Products</h1>
        <?php if (is_array($products) && count($products)) { ?>
            <?php foreach($products as $product) { ?>
                    <a href="<?php echo $product['url'] ?>"><?php echo $product['name'] ?></a>
            <?php } ?>
        <?php } ?>
  • frontend CMS block

    {{block type="fit_statistics/recent_products" name="fit_statistics_recent_products" template="fit_statistics/recent/products.phtml"}}

1 Answer 1


The composite products are not included in the reports.
Take a look at the method Mage_Reports_Model_Resource_Product_Collection::addOrderedQty

It contains these lines

$compositeTypeIds     = Mage::getSingleton('catalog/product_type')->getCompositeTypes();

and later

    $productJoinCondition = array(
        $adapter->quoteInto('(e.type_id NOT IN (?))', $compositeTypeIds),
        'e.entity_id = order_items.product_id',
        $adapter->quoteInto('e.entity_type_id = ?', $this->getProductEntityTypeId())

As you can see the composite products (configurable, grouped, bundle) are not included in the report.
You can rewrite the Mage_Reports_Model_Resource_Product_Collection class, add a new method similar to addOrderedQty from which you remove the restriction mentioned above and it might work.

  • Hi Marius, thanks for your reply. I've checked the code you pointed there but when i check the report at Reports > Product > Products Ordered, I can see all configurable products are displayed with the total count of all child products of them. I was asking how can I use the same method to populate my own collection. You can see my report screenshot below. pasteboard.co/24UnYUis.jpg
    – ilkb
    Commented Nov 12, 2015 at 9:55

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.