2

I have issue in product images.

Right now products are loading from cache from the path like below.

  site_url/media/catalog/product/cache/2765542505660baab28ecd555e27366e/t/m/image_name.jpg

This is leading to 404 error page.

But if we remove cache from the image url, the image is loading successfully.

like below one

 site_url/media/catalog/product/t/m/image_name.jpg

This will load the image correctly,

So I am planning to change the image url like this in all the pages.

How can load the image without cache path in product list page and in detail pages.

Can anyone look into this and update me ideas.

Thanks in advance!!

2 Answers 2

1

you shoud have product collection.

// return array, you can choose what you want
$image = $product->getMediaGalleryImages();
3
  • may i know in which file i need to use the above code? Commented Jun 10, 2019 at 7:47
  • @jafarpinjar you can inject \Magento\Catalog\Api\ProductRepositoryInterface and get product collection,then use the above code arbitrarily.
    – Tokey Tu
    Commented Jun 10, 2019 at 7:55
  • I need to make this change in all the pages wherever the products are loading Commented Jan 10, 2020 at 9:43
-1

You should try using the image resize command to re-generate images for valid cache path.

php bin/magento catalog:image:resize

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.