2

I just want to change/replace the custom function arguments, not constructor arguments.

This is third party module function, which have wrong argument.

public function addAttachment(\Fooman\EmailAttachments\Model\Api\AttachmentInterface $attachment)
{
    $this->message->createAttachment(
        $attachment->getContent(),
        $attachment->getMimeType(),
        $attachment->getDisposition(),
        $attachment->getEncoding(),
        $this->encodedFileName($attachment->getFilename())
    );
}

I want to replace argument from

\Fooman\EmailAttachments\Model\Api\AttachmentInterface $attachment

to

\VladimirPopov\WebForms\Model\Api\AttachmentInterface $attachment

Now, function looks like below:

public function addAttachment(\VladimirPopov\WebForms\Model\Api\AttachmentInterface $attachment)
{
    $this->message->createAttachment(
        $attachment->getContent(),
        $attachment->getMimeType(),
        $attachment->getDisposition(),
        $attachment->getEncoding(),
        $this->encodedFileName($attachment->getFilename())
    );
}

I have tried to overwrite this function by preference through the di.xml, But it's generating below error:

  [Exception]                                                                  
  Warning: Declaration of Vendor\Modulename\Model\Preference\Mail\Transp  
  ortBuilder::addAttachment(VladimirPopov\WebForms\Model\Api\AttachmentInterf  
  ace $attachment) should be compatible with VladimirPopov\WebForms\Model\Mai  
  l\TransportBuilder::addAttachment(Fooman\EmailAttachments\Model\Api\Attachm  
  entInterface $attachment) in 
  app/code/Vendor/Modulename/Model/Preference/Mail/TransportBuilder.php   
  on line 28

I have taken help from this article : https://alanstorm.com/magento_2_object_manager_argument_replacement/ But, here i got about only to change constructor arguments.

I don't know, is it possible for not? Please suggest.

  • For just workaround you can use File Base overriding, try this until find proper solution – Ashish Ranade Oct 16 '18 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.