I have successfully listed the best selling products, but how should I give it a link to open the same product in the product detail page whenever we click on it. The same product should open at the detail page which is clicked. Below is my code..
<?php
$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');
$conf = $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue("web/unsecure/base_url");
// echo $conf;
$collection->setPeriod('month');
//$collection->setPeriod('year');
//$collection->setPeriod('day');
foreach ($collection as $item) { ?>
<ol>
<li><a href=""><?php $productId = $item->getProductId(); //Product Id
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($productId);
$image = $conf."pub/media/catalog/product/".$product->getImage();
echo "<img src='$image'>" ?></a></li>
<li><?php echo $item->getProductName(); ?></li>
<li><?php echo $item->getProductPrice(); ?></li>
</ol>
<?php }
?>