Friend please help me how to get product images and thumbnail images.
-
you need to get Thumbnail product URL from Product collection?– Abhishek PanchalJul 16, 2018 at 19:19
-
so sir complete code given i have new developer so very problem understating. in magento code so please given on this code– pushpendraJul 16, 2018 at 19:23
-
I can not understand your question. Can you please specify where you want to show that thumbnail image?– Abhishek PanchalJul 16, 2018 at 19:25
-
wait i can explain– pushpendraJul 16, 2018 at 19:25
-
Yes. please explain in details.– Rohan HapaniJul 16, 2018 at 19:27
1 Answer
You need to inject the ImageBuilder class in our block :
protected $_imageBuilder;
public function __construct(
........
\Magento\Catalog\Block\Product\ImageBuilder $_imageBuilder
........
){
........
$this->_imageBuilder=$_imageBuilder;
........
}
public function getImage($product, $imageId, $attributes = [])
{
return $this->_imageBuilder->setProduct($product)
->setImageId($imageId)
->setAttributes($attributes)
->create();
}
=> This is default image type :
$imageType = 'product_base_image'; //For getting the base image
$imageType = 'product_small_image'; //For getting the small image
$imageType = 'product_thumbnail_image'; //For getting the thumbnail image
Now, get thumbnail image in phtml file :
<?php
$imageType = 'product_thumbnail_image'; //for thumbnail image
$image = $block->getImage($_item, $imageType);
?>
<img src = "<?php echo $image->getImageUrl(); ?>" />
Hope, It may be helpful for you !!