Getting product Image in PHTML in Magento2

   
    (1)  You have to load product to get thumbnail and url .

    <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $product = $objectManager->create('Magento\Catalog\Model\Product')->load($_item->getProduct()->getId());
    echo $product->getThumbnail();
    echo  $product->getProductUrl(); ?>


     (2) Get image url

    $imagewidth=200;
    $imageheight=200;
    $imageHelper  = $objectManager->get('\Magento\Catalog\Helper\Image');
    $image_url = $imageHelper->init($product, 'product_page_image_small')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl();
    echo $image_url

Comments

Popular posts from this blog

Get Swatch Text Product id of Configurable Product in Detail Page through Jquery Magento2

Through Postman Api send data through JSON and create simple product in Magento2