I am looking for a solution to a problem that I am having. I need to be able to render transactional emails for Magento 2.1.9 but they don’t need to be sent. I need to pass the email content to an internal API. I have googled and found nothing that can point me in the right direction to get the rendered email template.
I have tried to use the following to get the rendered email and I am not having any luck.
$ transport = $ this->_transportBuilder ->setTemplateIdentifier($ templateId) ->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => $ storeid]) ->setTemplateVars($ vars) ->setFrom($ identity) ->addTo($ cusomterData['email'], $ cusomterData['firstname']." ".$ cusomterData['lastname']) ->getTransport();
I var_dump transport and its null. I looked in the lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php to see what it was doing and in the ->getTransport method I see that its doing the following:
public function getTransport() { $ this->prepareMessage(); $ mailTransport = $ this->mailTransportFactory->create(['message' => clone $ this->message]); $ this->reset(); return $ mailTransport; }
I need to be able to email content when ever the state of the order changes from the following pending, processing, completed.
I am using a custom observer that fires on sales_order_save_after. The observer works I can get the order data and status. I just at a loss for how to get the rendered html content for the email.
If someone can point me in the right direction it would be a great help to me.