Skip to content

Delivery date in order email template – Magento 2.4.3-p2

Previously, we used the following module to load the email variable with a custom CreatedAt value. Because this is deprecated, it will not work anymore (https://devdocs.magento.com/guides/v2.4/frontend-dev-guide/templates/template-email-migration.html).

How can we modify the following, to keep using this custom CreatedAt from Magento 2.4.3-p2?

app/code/Mago/Delivery/registration.php

<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Mago_Delivery',
__DIR__
);

app/code/Mago/Delivery/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Mago_Delivery" setup_version="1.0.1">
   </module>
</config>

app/code/Mago/Delivery/etc/di.xml

<?xml version="1.0"?>
<config>
    <preference for="MagentoSalesModelOrder" type="MagoDeliveryModelRewriteOrder" />
</config>

app/code/Mago/Delivery/Model/Rewrite/Order.php

<?php

namespace MagoDeliveryModelRewrite;

class Order extends MagentoSalesModelOrder
{

    public function getDeliveryDate()
    {
        $orderDate = $this->getCreatedAt(); //ORDER CREATED DATE
        return date('Y-m-d', strtotime($orderDate. ' + 10 days'));
    }

}

Finally in your email template you can get this date by:

{{var order.getDeliveryDate()}}