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
Post a Comment