How to get best selling product with its image by object manager in magento2 .phtml file ???
1 Answer
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());
}
-
1Thanks 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] => )– souravFeb 20, 2018 at 16:05