I am trying to get bestseller products on homepage using product collection in Magento 2. I only got Most Viewed product listing (?) and I am not getting bestseller products.
Here is my code:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productCollection = $objectManager->create('Magento\Reports\Model\ResourceModel\Product\CollectionFactory'); $collection = $productCollection->create() ->addAttributeToSelect('*') ->addAttributeToFilter('status','1') ->setPageSize(8) ->load();
Can someone tell me which ResourceModel I need to load? I tried with:
Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory`enter code here`
But didn't helped (I got some error with that code and that resource).