I'm trying to get Best Seller Product collection using below code, but it will not display any data

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productCollection = $objectManager->create('\Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory');
$collection = $productCollection->create()->setModel('Magento\Catalog\Model\Product')->setPeriod('yearly');

How to get Best Seller Product collection ?

  • it might not working because you have set "yearly" instead of "year", please check my ans for more information. Feb 13, 2019 at 9:51

4 Answers 4


Please try this code to get best seller product collections using objectManager.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productCollection = $objectManager->create('Magento\Reports\Model\ResourceModel\Report\Collection\Factory'); 
$collection = $productCollection->create('Magento\Sales\Model\ResourceModel\Report\Bestsellers\Collection'); 


foreach ($collection as $item) {
  • Hi Aasim Goriya I have used same logic in my custom block but it is displaying empty records (those are not available currently at admin end products grid) could you please advise? Apr 9, 2019 at 10:43
  • Exclude empty records using filters at code level Apr 9, 2019 at 10:44
  • @AssimGoriya, How can i get latest month's best seller product? any Idea? Apr 26, 2019 at 10:02

But if you want latest bestselling product collection for the day please use this code in block

public function getBestsellerProduct(){

$resourceCollection = $this->_resourceFactory->create('Magento\Sales\Model\ResourceModel\Report\Bestsellers\Collection');   
$resourceCollection->setPeriod('day')->addStoreFilter(1)->getSelect()->order('period DESC');
return $resourceCollection;

  • 1
    same for latest month's best seller product instead of 'day' replace it by 'month' Apr 2, 2021 at 8:21

To get best seller collection, try to do as follows:

Step 1: Firstly, Create one block file on our custom extension

add Blockname.php in the following path


namespace Vendor\Extension\Block;

use Magento\Catalog\Block\Product\Context;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory as BestSellersCollectionFactory;
use Magento\Framework\View\Element\Template;
use Magento\Store\Model\StoreManagerInterface;

class Blockname extends Template
    protected $_bestSellersCollectionFactory;
    protected $_productCollectionFactory;
    protected $_storeManager;

    public function __construct(
        Context $context,
        CollectionFactory $productCollectionFactory,
        StoreManagerInterface $storeManager,
        BestSellersCollectionFactory $bestSellersCollectionFactory,
    ) {
        $this->_bestSellersCollectionFactory = $bestSellersCollectionFactory;
        $this->_storeManager = $storeManager;
        $this->_productCollectionFactory $productCollectionFactory;
    public function getProductCollection()
        $productIds = [];
        $bestSellers = $this->_bestSellersCollectionFactory->create()
        foreach ($bestSellers as $product) {
            $productIds[] = $product->getProductId();
        $collection = $this->_productCollectionFactory->create()->addIdFilter($productIds);
        return $collection;

    public function getStoreId(){
        return $this->_storeManager->getStore()->getId();

Step 2: After the above step Insert the below code in phtml file at the following path.


$collection = $block->getProductCollection();
foreach ($collection as $_product) 
    echo $product->getName() . ' - ' . $product->getProductUrl() . '<br />';

Step 3: Flush Cache and view the result.


https://github.com/viveksh2021/Bestseller please follow custom module for bestseller product collection on daily basis

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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