1

I tried below code to get items from order in email template order_update.html

{{layout handle="sales_email_order_items" order=$order area="frontend"}}

but above one not working for me , so i tried like below,

 {{block class='Magento\\Framework\\View\\Element\\Template' area='frontend' template='Magento_Sales::email/items.phtml' order=$order"}}

This one throws error like below,

exception 'BadMethodCallException' with message 'Missing required argument $debugHintsPath 

if anybody have idea means please tell me

1 Answer 1

0

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

  1. 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>
  1. 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);
    }
}
  1. 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

  1. 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.