Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7645393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:55:50+00:00 2026-05-31T09:55:50+00:00

In Magento I’m using the following code to get a bestsellers data collection: Model

  • 0

In Magento I’m using the following code to get a bestsellers data collection:

Model Function:

  public function bestSellers($limit = 12){

    $storeId    = Mage::app()->getStore()->getId();
    $_productCollection = Mage::getResourceModel('reports/product_collection')
        ->addOrderedQty()
        ->addAttributeToSelect('id')
        ->setStoreId($storeId)
        ->addStoreFilter($storeId)
        ->setOrder('ordered_qty', 'desc') //best sellers on top
        ->setPageSize($limit); 

    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($_productCollection);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($_productCollection);

    return $_productCollection; 

}

Block Output:

<?php $products = Mage::getModel('tabs/collections')->bestSellers($limit); ?>
<pre>
    <?php print_r($productCollection->getData()); ?>
</pre>

However it returns nothing when the addVisibleInCatalogFilterToCollection line is used in the model function, but if I remove the addVisibleInCatalogFilterToCollection line, then it returns an array of expected bestselling product data (including the ones that shouldn’t be visible in the catalog).

How can I return my array of data with the visibility filter working as it should? Rather than returning nothing. Very confused. Thanks in advance!

Here’s the getSelect:

   SELECT SUM(order_items.qty_ordered) AS `ordered_qty`, `order_items`.`name` AS `order_items_name`, `order_items`.`product_id` AS `entity_id`, `e`.`entity_type_id`, `e`.`attribute_set_id`, `e`.`type_id`, `e`.`sku`, `e`.`has_options`, `e`.`required_options`, `e`.`created_at`, `e`.`updated_at`, `cat_index`.`position` AS `cat_index_position` FROM `sales_flat_order_item` AS `order_items`
  INNER JOIN `sales_flat_order` AS `order` ON `order`.entity_id = order_items.order_id AND `order`.state <> 'canceled'
  LEFT JOIN `catalog_product_entity` AS `e` ON (e.type_id NOT IN ('grouped', 'configurable', 'bundle')) AND e.entity_id = order_items.product_id AND e.entity_type_id = 4
  INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id='1' AND cat_index.visibility IN(2, 4) AND cat_index.category_id='2' WHERE (parent_item_id IS NULL) GROUP BY `order_items`.`product_id` HAVING (SUM(order_items.qty_ordered) > 0) ORDER BY `ordered_qty` desc
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:55:51+00:00Added an answer on May 31, 2026 at 9:55 am

    Here is my Block which i use to obtain bestsellers. It also does simple products that are variants of parental configurable products, to configurable products (works correctly only if one simple products is assigned to max 1 configurable product): http://devblog.fishol.pl/bestselling-products-in-magento/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Inside Magento templating code I want to get the width and height of the
Magento uses a factory pattern for instantiating objects from classes $model = Mage::getModel('catalog/product'); //Mage_Catalog_Model_Product
hai I have a magento web site. In this the search function compare with
This is very basic magento question i guess. I want to first get all
In Magento, if you need to get / fetch the Shopping Cart's Item details,
I am using Magento 1.5 and have around 33,450 products on my site. 32000
I'm using Magento v2 web service in WS-I compliant mode when try to list
I am using Magento eCommerce and I have modified my header.phtml via the Blank
In magento, it is possible to get the simple products associated to a configurable
Using Magento i want to create website where user can upload their products to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.