Adds

How to load product collection in Magento 2

 How to load product collection in Magento 2



Here is The code:

<?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 */
$collection = $productCollection->addAttributeToSelect('*')
            ->load();
foreach ($slt_collection as $slt_product){

     $Name  = $slt_product->getName();
     $Image = $slt_product->getImage();
     $Price = $slt_product->getPrice();
     $Url = $slt_product->getProductUrl();

     // echo $Image;
?>
<a href="<?php echo $slt_product->getProductUrl(); ?>">
<img src="<?php echo $block->getBaseUrl()."pub\media\catalog\product".$Image; ?>" width="200px" height="200px">
   <h4>Name: <?php echo $Name;?></h4>
      <h4>₹ <?php echo $Price;?></h4>
</a>
}  
?>

No comments

Powered by Blogger.