I am trying to generate a "best selling products" list on my magento site. I tried following the answer from here. This works okay, however, I realized that this is only ideal for simple products. I am trying to create the ranking for configurable products so I believe I need to get the total orders for the simple products first which I'm not sure how I can do programmatically. This is basically the idea I have in mind:
Get the simple products associated to a configurable product
Get the total orders for each simple product and sum them up
Pass the total sum to configurable products again (i'm thinking of using an array here) then call the necessary data ordered by ranking.
So far I have come up with this code:
$storeId = Mage::app()->getStore()->getId();
$_collection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', 'configurable');
foreach($_collection as $c):
$configurable = $c->getTypeInstance()->getUsedProductIds();
foreach($configurable as $_config):
$_simple = Mage::getModel('catalog/product')->load($_config);
echo $_simple->getName()."<br/>";
echo "qty:".(int)$_simple->ordered_qty."<br/>";
endforeach;
endforeach;
However, while trying to test it, all of my quantities return 0 so I'm stuck. How do I implement the ranking for configurable products? Please advise. Also, if possible, I'd like to make as little changes to the core files as possible.
Also, I have this ranking list limited to 10 and if the other products have 0 quantity sold, then they will automatically be sorted alphabetically. Same goes if for example 2 products have the same amount sold.