Preference Conflict with VladimirPopov WebForms

There is currently a preference conflict between Email Attachments and the VladimirPopov\WebForms extension.  

If you are getting an error message like this when sending an email with attachment:

[13-Sep-2017 09:49:57 UTC] PHP Fatal error: Uncaught TypeError: Argument 1 passed to VladimirPopov\WebForms\Model\Mail\TransportBuilder::addAttachment() must be an instance of VladimirPopov\WebForms\Model\Api\AttachmentInterface, instance of Fooman\EmailAttachments\Model\Attachment given, called in /var/www/vendor/fooman/emailattachments-m2/src/Model/SenderBuilder.php on line 51 and defined in /var/www/vendor/vladimirpopov/webforms2/Model/Mail/TransportBuilder.php:15
Stack trace:
#0 /var/www/vendor/fooman/emailattachments-m2/src/Model/SenderBuilder.php(51): VladimirPopov\WebForms\Model\Mail\TransportBuilder->addAttachment(Object(Fooman\EmailAttachments\Model\Attachment))
#1 /var/www/vendor/magento/module-sales/Model/Order/Email/Sender.php(77): Fooman\EmailAttachments\Model\SenderBuilder->send()
#2 /var/www/vendor/magento/module-sal in /var/www/vendor/vladimirpopov/webforms2/Model/Mail/TransportBuilder.php on line 15

then in vendor/vladimirpopov/webforms2/Model/Mail/TransportBuilder.php change

public function addAttachment(Api\AttachmentInterface $attachment)
to
public function addAttachment(\Fooman\EmailAttachments\Model\Api\AttachmentInterface $attachment)

If it complains about the method addAttachment missing you can edit vendor/vladimirpopov/webforms2/Model/Mail/TransportBuilder.php to include the below

class TransportBuilder extends \Magento\Framework\Mail\Template\TransportBuilder
{
    /**
     * @param \Fooman\EmailAttachments\Model\Api\AttachmentInterface $attachment
     */
    public function addAttachment(\Fooman\EmailAttachments\Model\Api\AttachmentInterface $attachment)
    {
        $this->message->createAttachment(
            $attachment->getContent(),
            $attachment->getMimeType(),
            $attachment->getDisposition(),
            $attachment->getEncoding(),
            $this->encodedFileName($attachment->getFilename())
        );
    }

Still need help? Contact Us Contact Us