Magento 2.1 – Get Best Seller Product on Daily Basis

best-sellermagento-2.1product

There are some tables related to bestseller in Magento 2 and it is using following tables to get best product collection.

sales_bestsellers_aggregated_daily
sales_bestsellers_aggregated_monthly
sales_bestsellers_aggregated_yearly 

I think, magento2 use sales_bestsellers_aggregated_yearly table for best seller products. I am using \Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory and it is working fine.

I am getting the bestseller collection yearly basis. How can i achieve bestseller collection by monthly basis or daily basis.

Thanks in advance.

Best Answer

Try this

$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'); 

//$collection->setPeriod('month');
//$collection->setPeriod('year');
$collection->setPeriod('day');

foreach ($collection as $item) {
    print_r($item->getData());
}
Related Topic