3

How to get best selling product with its image by object manager in magento2 .phtml file ???

1 Answer 1

2

Try below code :

$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());
}
1
  • 1
    Thanks for your reply. that code working but product image, product url not showing. Plz check the attached output bellow. Array ( [period] => 2018-01-01 [qty_ordered] => 1.0000 [product_id] => 1483 [product_name] => Minerva LumaTech™ V-Tee-XS-Blue [product_price] => 0.0000 [orig_data] => )
    – sourav
    Feb 20, 2018 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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