Magento 2 - How to retrieve product informations
In Magento 2 proposed to use service layer for this.
Try use \Magento\Catalog\Model\ProductRepository::getById
method to get product by id
Magento 2 recommends to use Factories
for loading all Models. Here is how you should do it:
Above your class add this line:
use Magento\Catalog\Model\ProductFactory;
Now create class property:
protected $productFactory;
In your constructor, add dependency:
public function __construct( ProductFactory $productFactory ) { $this->productFactory = $productFactory; }
Now load product as below:
$_product = $this->productFactory->create()->load(<product_id>);
On top of others answers, I highly suggest using the following service contracts methods:
\Magento\Catalog\Api\ProductRepositoryInterface::getById
: to load a product by id\Magento\Catalog\Api\ProductRepositoryInterface::get
: to load a product by sku