2

Normally I would do something like

<?php

use \Magento\Sales\Model\Order\Email\Sender\OrderSender;
use \Magento\Sales\Model\Order;

class MyClass
{
    private $orderSender;
    private $order;

    public function __construct(
        OrderSender $orderSender,
        Order $order
    ) {
        $this->orderSender = $orderSender;
        $this->order = $order;
    }

    public function sendEmail($import, $orderItems)
    {
        $this->order->load($orderId);
        $this->orderSender->send($order, true);
    }
}

I have noted $this->order->load() has been deprecated but $this->orderSender->send() expects \Magento\Sales\Model\Order

Therefore my question is how would I send order confirmation emails without using deprecated methods.

Also as a note "Asynchronous sending" for is disabled Sales Emails

1 Answer 1

6

Try repository for loading order. So your modified class looks like:

<?php

use \Magento\Sales\Model\Order\Email\Sender\OrderSender;
use Magento\Sales\Api\OrderRepositoryInterface;

class MyClass
{
    private $orderSender;
    private $order;

    public function __construct(
        OrderSender $orderSender,
        OrderRepositoryInterface $orderRepository
    ) {
        $this->orderSender = $orderSender;
        $this->orderRepository = $orderRepository;
    }

    public function sendEmail($import, $orderItems)
    {
        $order = $this->orderRepository->get($orderId);
        $this->orderSender->send($order, true);
    }
}

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.