Magento BestSeller Module - Summing Configurable Products And Adding Them Back In

Magento BestSeller Module - Summing Configurable Products And Adding Them Back In

October 18, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento BestSeller Module - Summing Configurable Products And Adding Them Back In

Magento BestSeller Module: Summing Configurable Products And Adding Them Back In

Introduction

The Magento bestseller module is an essential tool for e-commerce stores looking to highlight their most popular products. However, when it comes to configurables, the default implementation falls short - it displays these complex products with a quantity ordered of 0 on the frontend. This post will guide you through summing the amount sold of simple products attached to configurable items and feeding this information back into the bestseller module.

The Challenge

The primary issue lies in how Magento handles configurable products within the Luxe_Bestsellers_Model_Mysql4_Product_Collection class. Currently, it doesn’t account for the simple products nested under configured ones when calculating the ‘ordered_qty’.

Additionally, in the Luxe_Bestsellers_Block_List class responsible for fetching and displaying the bestselling products, we need to ensure that the collection correctly includes and orders these configured items based on their total sold quantity.

Step-by-Step Solution

Modifying the Collection Model

Let’s start by updating the addOrderedQty method in your Luxe_Bestsellers_Model_Mysql4_Product_Collection class. We’ll use Magento’s built-in product association to fetch simple products linked to configurable ones:

public function addOrderedQty($from = '', $to = '', $getComplexProducts=false)
{
    // Existing code...

    $_joinCondition = $this->getConnection()->quoteInto(
            'order.entity_id = order_items.order_id AND order.state<>?', Mage_Sales_Model_Order::STATE_CANCELED
     );
     $_joinCondition .= $dateFilter;

     if ($getComplexProducts) {
         // Fetching all associated simple products for configurable items
         $this->getSelect()->joinInner(
             array('associated' => $this->getTable('catalog/product_super_attribute')),
             "e.entity_id = associated.product_id AND associated.parent_product_id IS NOT NULL",
             array()
         );
     }

    // Existing code...
}

Calculating the Total Quantity

Next, we need to compute the total sold quantity for each configurable item by aggregating the ‘ordered_qty’ of its simple products.

public function addOrderedQty($from = '', $to = '', $getComplexProducts=false)
{
    // Existing code...

    if ($getComplexProducts) {
        $this->getSelect()->joinLeft(
            array('associated_items' => $qtyOrderedTableName),
            "order_items.order_id = associated_items.order_id AND associated_items.product_id = associated.super_attribute_id",
            array('associated_ordered_qty' => "SUM(associated_items.{$qtyOrderedFieldName})")
        );
    }

    // Existing code...
}

Updating the Ordering

Finally, adjust the ordering clause to consider the calculated total quantity for configured items:

$this->getSelect()->order(
    array('COALESCE(total_ordered_qty, ordered_qty) DESC', 'ordered_qty DESC')
);

Conclusion

By updating the collection model as described above, you’ll ensure that your configurable products are correctly aggregated and displayed in the bestseller module based on their total sold quantity.

This solution leverages Magento’s built-in product association to fetch related simple items and calculates their combined ordered quantity. The ordering clause is then modified to consider this total when listing the most popular products.

Remember, these changes should be implemented in your custom theme or module to avoid conflicts with core files. Always create a backup before making modifications to your live site.

Happy coding! For more Magento development insights and resources, feel free to explore https://laravelcompany.com.

Catalog Database Extensions Configuration

Our network