2

In Magento2.2.4, I load product and get image path. But, It's just display image path like this : /m/b/mb01-blue-0.jpg

I want to get cached image path url. But, It's not get from which collection I load.

How to get it?

Please help me.

1

Add this code in your block :

protected $_imageHelper;

public function __construct(
    .........................
    \Magento\Catalog\Helper\Image $imageHelper,
    .........................
)
{
    .........................
    $this->_imageHelper = $imageHelper;
    .........................
}

public function getImageFullPath($product)
{
    return $this->_imageHelper->init($product,'image')->setImageFile($product->getImage())->getUrl();
}

After, Call this function in your phtml :

$imagePath = $block->getImageFullPath($currentProduct);

Clean cache and refresh the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy