You only need to pass in the missing parameter order_id to the template to use sales_email_order_items to display the order item grid
- create vendor/module_name/etc/di.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Sales\Model\Order\Email\Sender\OrderCommentSender" type="vendor\module_name\Model\Order\Email\Sender\OrderCommentSender" />
</config>
- create vendor/module_name/Model/Order/Email/Sender/OrderCommentSender.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace vendor\module_name\Model\Order\Email\Sender;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Email\Container\OrderCommentIdentity;
use Magento\Sales\Model\Order\Email\Container\Template;
use Magento\Sales\Model\Order\Email\NotifySender;
use Magento\Sales\Model\Order\Address\Renderer;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\DataObject;
/**
* Class OrderCommentSender
*/
class OrderCommentSender extends \Magento\Sales\Model\Order\Email\Sender\OrderCommentSender
{
/**
* @var Renderer
*/
protected $addressRenderer;
/**
* Application Event Dispatcher
*
* @var ManagerInterface
*/
protected $eventManager;
/**
* Send email to customer
*
* @param Order $order
* @param bool $notify
* @param string $comment
* @return bool
*/
public function send(Order $order, $notify = true, $comment = '')
{
$this->identityContainer->setStore($order->getStore());
$transport = [
'order' => $order,
'order_id' => $order->getId(),
'comment' => $comment,
'billing' => $order->getBillingAddress(),
'store' => $order->getStore(),
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
'order_data' => [
'customer_name' => $order->getCustomerName(),
'frontend_status_label' => $order->getFrontendStatusLabel()
]
];
$transportObject = new DataObject($transport);
/**
* Event argument `transport` is @deprecated. Use `transportObject` instead.
*/
$this->eventManager->dispatch(
'email_order_comment_set_template_vars_before',
['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject]
);
$this->templateContainer->setTemplateVars($transportObject->getData());
return $this->checkAndSend($order, $notify);
}
}
- run the following command:
sudo php bin/magento setup:upgrade && sudo php bin/magento setup:di:compile && php bin/magento setup:static-content:deploy en_US -f && php bin/magento indexer:reindex && php bin/magento cache:clean && php bin/magento cache:flush && sudo chmod 777 * -R
use it in order_update.html
{{layout handle="sales_email_order_items" order_id=$order_id area="frontend"}}
Note that the parameter passed in sales_email_order_items is $order_id, using $order will be invalid