0

I need to add a product image to a new order email after successful checkout.

Which file do I need to override to affect only new order email template?

Should I override it in app/code or app/design?

Can anyone suggest a proper way to do it!?

1

As you want to follow the best approach then you have to use the modular approach means create a module under app/code and do what override template and add new class whatever your needs.

If you want to override add the image as new column like Items,Qty,Price, then you have rewrite Magento_Sales::email/items.phtml from your module, and you have to copy all code of vendor/magento/module-sales/view/frontend/templates/email/items.phtml and past at your module items.phtml.

Create sales_email_order_items.xml app/code/MyVendor/MyModule/view/frontend/layout/ and rewrite override code at here.

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" >
    <body>
        <referenceBlock name="items" template="MyVendor_MyModule::email/items.phtml"/>
    </body>
</page>

and templates items.phtml file location app/code/MyVendor/MyModule/view/frontend/templates/email

Note that you have to copy all code of vendor/magento/module-sales/view/frontend/templates/email/items.phtml and past at your module items.phtml.

Now, you have to render the image to phtml file means vendor/magento/module-sales/view/frontend/templates/email/items/order/default.phtml

So, you have to override the default.phtml , but before want to create a helper class where I will create a method which product image path.

0

Copy following file

vendor/magento/module-sales/view/frontend/templates/email/items/order/default.phtml

to

app/design/frontend/Vendor/Theme/Magento_Sales/templates/email/items/order/default.phtml

In this file you have ordered item information. You can add image by load product by id and get image from product object.

Please let me know still if you have any question.

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.