I create a custom module to send email to customer and admin separately if i try to override the core file in my custom module its shown error .Error come when i override the [ sender.php ] file in my custom module could you please suggest me regarding this so i can proceed forward.

enter image description here

  • Give your code please (OrderSender.php and di.xml)
    – Harun
    Mar 29, 2023 at 5:59

2 Answers 2


I am suggesting not use Plugin and it little complicated at this method and

Suggesting to use Class rewrite using .

di.xml code

<?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\OrderSender" type="Hatrid\OrderConfirmation\Reurite\liagento\Sales" />

Rewrite class StackExchange\Magento\Rewrite\OrderSender.php


use Magento\Sales\Model\Order;
use Magento\Framework\DataObject;

class Sales extends \Magento\Sales\Model\Order\Email\Sender\OrderSender{

     * @var \Magento\Catalog\Api\ProductRepositoryInterface
    private $productRepository;

    public function __construct(
            \Magento\Sales\Model\Order\Email\Container\Template $templateContainer, 
            \Magento\Sales\Model\Order\Email\Container\OrderIdentity $identityContainer, 
            \Magento\Sales\Model\Order\Email\SenderBuilderFactory $senderBuilderFactory,
            \Psr\Log\LoggerInterface $logger,
            \Magento\Sales\Model\Order\Address\Renderer $addressRenderer,
            \Magento\Payment\Helper\Data $paymentHelper,
            \Magento\Sales\Model\ResourceModel\Order $orderResource,
            \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig,
            \Magento\Framework\Event\ManagerInterface $eventManager,
            \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
     ) {
                $this->productRepository = $productRepository;
    protected function prepareTemplate(Order $order){

        // your custom code here

  • i want to need of sender.php file to override because this is use abstract class . so what can i do to override the sender.php Mar 29, 2023 at 6:06
  • First write your code exactly what you do for override that.............
    – Jay Parmar
    Mar 29, 2023 at 6:07

You can also use event observer for override the sender.php

check this one I think this will more helpful for you

Magento 2 :How to override Magento\Sales\Model\Order\Email\Sender.php model?

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.