Magento – Magento 2 product images always returning the placeholder image

magento2placeholderproduct-images

I've written a plugin, and in it I'm trying to obtain the product image url like this:

$generalInfo = array(
    'image_url' => $this->_imageHelper->init($product, 'product_base_image')
        ->constrainOnly(FALSE)
        ->keepAspectRatio(TRUE)
        ->keepFrame(FALSE)
        ->getUrl()
);

The problem is that this is returning the placeholder image url, not the actual product image url. The product does have images, and they are visible when visiting the product page, but from the php code Magento2 is not able to find them.

Is there any other method of obtaining product images that is more reliable? How does Magento2 obtain the correct image url for displaying on the frontend?

Best Answer

Flush Catalog Image Cache and regenerate new cache images by running below Magento CLI command.

php bin/magento cache:images/resize
Related Topic