Wrong product image in sales order email in production mode - Magento2.3.5

We use the following code to load the product image in the sales order email.
This works perfect in developer mode, but when we switch to production mode the images are not correct for those who do not got any image.

In that case the product that does not have any image, not the placeholder is shown as you should expect, but the same productimage as the product above is displayed.

The next product in line that does have any image, that is then displayed well.


enter image description here

How can we solve this?

Template: /app/design/frontend/theme/theme/Magento_Sales/templates/email/items/invoice/default.phtml


<?php $_item = $block->getItem()
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product_id = $_item->getProductId();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);
$_imagehelper = $objectManager->get('MagentoCatalogHelperImage');
$image_url = $_imagehelper->init($product, 'cart_page_product_thumbnail')->getUrl();?>

<img src="<?= $image_url;?>"

Magento Asked by JGeer on December 29, 2020

1 Answers

One Answer

you may use a helper like below:


namespace MbsOrderEmailHelper;

use MagentoFrameworkAppHelperAbstractHelper;
use MagentoFrameworkAppHelperContext;

class GetItemImage extends AbstractHelper
     * @var MagentoCatalogBlockProductImageBuilder
    private $imageBuilder;

    public function __construct(
        Context $context,
        MagentoCatalogBlockProductImageBuilder $imageBuilder
    ) {
        $this->imageBuilder = $imageBuilder;

    public function getCartItemImage($item)
        if ($item->getProduct() instanceof MagentoCatalogModelProduct) {
            return $this->imageBuilder->create($item->getProduct(), 'category_page_grid')->toHtml();

        return '';

then this helper will need to be used in your email template: the line below will output an image: the default email template for item in Magento is vendor/magento/module-sales/view/frontend/templates/email/items/order/default.phtml. You may have customised this template and therefore you will need to fetch it within your theme folder.

<?= $helper->getCartItemImage($_item) ?>

Correct answer by Herve Tribouilloy on December 29, 2020

Add your own answers!

Related Questions

Magento 2: Requested store is not found in product

2  Asked on January 3, 2021 by cesarchris710


Slow Admin Orders Grid – Magento 2.3.3 Community

0  Asked on January 2, 2021 by alex-heaton


Sorting a custom column – Customer Grid

2  Asked on December 31, 2020 by kiwistastegood


Mobile-friendly test: Couldn’t load 36 page resources?

1  Asked on December 31, 2020 by vinod-kumar


Magento 2 get Admin session in frontend

1  Asked on December 29, 2020 by ramesh


Whitespace before SOAP declaration

3  Asked on December 29, 2020 by boruch


display magento2 menu based on the customer login

0  Asked on December 29, 2020 by venkata-prasad


Override a controller in magento 1.9

0  Asked on December 29, 2020 by mahesh1343


Move block after price using layout xml in M1.9

0  Asked on December 27, 2020 by sam-provides


Ask a Question

Get help from others!

© 2022 All rights reserved.