Category Archives: Development

May 18, 2016 6:50 am
image_round

Magento2 How to load product collection by id

I got product collection in my custom template using following code

<?php 
 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
  $productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');

foreach ($productCollection as $product) {
           $product_id=$product['entity_id'];
           echo $_product->getName();
}?>

Magento2 How to load product collection by id

I got product collection in my custom template using following code

<?php 
 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
  $productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');

foreach ($productCollection as $product) {
           $product_id=$product['entity_id'];
           echo $_product->getName();
}?>