This question already has an answer here:

I got the product collection in my custom template using the following snippet:

<?php 
 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

 /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection
  $productCollection */
  $productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
 /** Apply filters here */

 $productCollection->load();

 foreach ($productCollection as $p)
 {
  echo "<pre>";
  print_R($p->getData());
 }
Here i got array with product id like this

 Array
(
[entity_id] => 1
[attribute_set_id] => 4
[type_id] => virtual
[sku] => Double Corona Natural (box of 25)
[has_options] => 0
[required_options] => 0
[created_at] => 2015-12-23 09:20:38
[updated_at] => 2015-12-23 09:20:38
[is_salable] => 1
)

From this entity_id, how can I load products like we did in Magento 1.x?

$_product = Mage::getModel('catalog/product')->load($productID);  

marked as duplicate by Alex Paliarush, 7ochem, Qaisar Satti, Amit Bera, liyakat Dec 23 '15 at 12:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 54 down vote accepted

object method

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);

Factory Method

<?php
namespace Test\Module\Block;

class Product extends \Magento\Framework\View\Element\Template
{

  protected $_productloader;  


  public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Catalog\Model\ProductFactory $_productloader

    ) {


        $this->_productloader = $_productloader;
        parent::__construct($context);
    }
    public function getLoadProduct($id)
    {
        return $this->_productloader->create()->load($id);
    }

}

phtml file code

$product=$this->getLoadProduct(20);
echo $product->getName();

In Magento 2.1

<?php
    namespace Test\Module\Block;
    use Magento\Catalog\Api\ProductRepositoryInterface;
    class Product extends \Magento\Framework\View\Element\Template
     {
          protected $productRepository; 
          protected $_storeManager; 

          public function __construct(
            \Magento\Framework\App\Action\Context $context,
            ProductRepositoryInterface $productRepository
          ) {
              parent::__construct($context);

              $this->productRepository = $productRepository;
          }
          public function getProduct()
          {

              $productId=1;
              return $product = $this->productRepository->getById($productId);
          }
      }

Reference

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