Automating Custom Email Logic With Magento 2

Jonathan Anderson
E-Commerce Manager

This is a weekly series detailing common issues that can occur during Magento 2 custom development. Check back next week for more solutions!

In our last post, we focused on creating custom bundled products. This week, we’re continuing with our case-study of Milk Jar Cookies and how we modified ShipmentSender to allow for custom content to be delivered to the customer, based on their shipping preference.

Depending on whether a customer chose pick-up, courier delivery, or traditional UPS shipping, MJC wanted their customers to receive a custom confirmation based on their chosen preference. The email templating system had no way to parse the different choices, since they were a custom addition, so we had to programmatically create custom variables.

The main issue with the built-in email template was that logical statements were not a native feature, forcing us to create a new module to extend ShipmentSender’s class send function. This alteration modified the transport options which are an array of variables that pass onto the template.

However, we noticed that the extension that deals with the OrderDeliveryDate (which allows for a time and date to be part of a shipping option) was already overriding this file so that they can make their arrival_date and time_slot properties available in the email templates.

When a new customer places their order, the system sends them an account confirmation email and an order confirmation email. Once MJC is able to process the order on their end and fulfill the shipping method of choice, the Ship Station integration will automatically send the customer an email with their tracking number, or delivery/pickup window.

Once MJC is able to process the order on their end and fulfill the shipping method of choice, the Ship Station integration will automatically send the customer an email with their tracking number, or delivery/pickup window.

- Jonathan AndersonE-Commerce Manager | 

Filed under: <E-commerce>