I'm trying to get in the home page 12 bestseller products with this code:

$_productCollection = Mage::getResourceModel('reports/product_collection')
                                                    ->setOrder('ordered_qty', 'desc');

The problem is that with this code I have the bestsellers of all stores.

The parameter ->setStoreId() and ->addStoreFilter don't work.

Any idea?


With the code of Rakesh Donga get the next list: enter image description here

These products have the status "disabled" in backend.

In the backend go to Reports -> Products -> Products ordered and get this products:

enter image description here

  • store id how to get it? – Rakesh Donga Feb 11 at 16:57
  • with this: $storeId = Mage::app()->getStore()->getId(); – str_lml Feb 11 at 16:58
  • here another store products coming? – Rakesh Donga Feb 11 at 16:59
  • No, return the correct id but the collection of products are about all the websites – str_lml Feb 11 at 17:00
  • check my answer – Rakesh Donga Feb 11 at 17:06

Did you try using following code:


 * Add store restrictions to product collection
 * @param  array $storeIds
 * @param  array $websiteIds
 * @return Mage_Reports_Model_Resource_Product_Collection
public function addStoreRestrictions($storeIds, $websiteIds)
    if (!is_array($storeIds)) {
        $storeIds = array($storeIds);
    if (!is_array($websiteIds)) {
        $websiteIds = array($websiteIds);

    $filters = $this->_productLimitationFilters;
    if (isset($filters['store_id'])) {
        if (!in_array($filters['store_id'], $storeIds)) {
        } else {
    } else {

    return $this;

So your case:

$_productCollection = Mage::getResourceModel('reports/product_collection')
                                                    ->addStoreRestrictions([$storeId], [$websiteIds])
                                                    ->setOrder('ordered_qty', 'desc');
  • I put this: ->addStoreRestrictions([$storeId], [Mage::getModel('core/store')->load($storeId)->getWebsiteId()]) and return an incorrect list – str_lml Feb 11 at 17:05


Need override the file:


Add the next function at the end of the file:

 public function addWebsiteFilterPurchased()

    $storeId = Mage::app()->getRequest()->getParam('store');
    if($storeId == null){
        $storeId = Mage::app()->getStore()->getStoreId();

    $this->getSelect()->where('order_items.store_id IN (?)', (array)$storeId);

    return $this;

And use it:

$_productCollection = Mage::getResourceModel('reports/product_collection')
                                                    ->setOrder('ordered_qty', 'desc');

try this following way

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

            $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}",
                    array('SUM(aggregation.qty_ordered) AS sold_quantity')
                ->order('sold_quantity DESC');

  • With this code i have other products respect the report of products ordered. See my first post to see the images – str_lml Feb 13 at 8:50

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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