Based on certain aspects of an order I want to replace the email template being used. I'd preferably like to use a plugin to do this as I feel this is the proper Magento 2 way.

Unfortunately most of the methods i'd like to intercept are protected. Thanks Magento. Anyway, the soonest place I can find to do this is in Magento\Sales\Model\Order\Email\SenderBuilder and using a plugin before the send() method.

I'm getting the error :

Missing argument 2 for 
called in /var/www/public/vendor/magento/framework/Interception/Interceptor.php on line 123 
and defined in /var/www/public/vendor/namespace/modulename/Model/Plugin/ReplaceNewOrderEmailPlugin.php on line 9

Here is my code :


<type name="Magento\Sales\Model\Order\Email\SenderBuilder">
        <plugin name="Company_Namespace::ReplaceNewOrderEmail"

Plugin file

use Magento\Sales\Model\Order\Email\SenderBuilder;

class ReplaceNewOrderEmailPlugin

    public function beforeSend($subject, $result)
        die('plugin working');
        return $result;

and for good measure, here is the function i'm trying to plugin to


public function send()


        $copyTo = $this->identityContainer->getEmailCopyTo();

        if (!empty($copyTo) && $this->identityContainer->getCopyMethod() == 'bcc') {
            foreach ($copyTo as $email) {

        $transport = $this->transportBuilder->getTransport();

Does anyone have any ideas why i'm getting this ?

1 Answer 1


The before plug-in gives you access to the subject instance and the parameters being passed in. In this case the method you are targeting has no parameters and that's why the second argument doesn't exist. Also, I think you should use the around plug-in instead so that you can run your code or base code depending on the order. Using before, the base code will always run.

  • I will try it later on today and let you know. Thanks for helping!
    – Frank
    Oct 5, 2016 at 7:44

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.