1

I am in the process of trying to add a product image to each order item displayed on the sales/order/view page located inside the user account area of Magento2.

What is the most efficient way of retrieving the product image URL from inside the following template file?

app/design/frontend/[Vendor]/[theme_dir]/Magento_Sales/templates/order/items/renderer/default.phtml
1

You can use $_item->getProduct()->getImage() to get the product image.

1
  • Hi DMatthew, Thanks for your response. I'm not sure this is the best way. If an image is uploaded at 100MB then this method would return the 100MB image rather than return an optimised version which you can set the size of. Mar 21 '17 at 10:10
0

To get the product image I used the following helper:

$image_helper = $this->helper('Magento\Catalog\Helper\Image');

And then retrieved the image URL like so:

<img src="<?php echo $image_helper->init($_item->getProduct(), '[image id set inside view.xml goes here]')->getUrl() ?>" alt="<?php echo $block->escapeHtml($_item->getName()) ?>">

Your Answer

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

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