Ich muss PDF und Bilder mit Bestell-E-Mail anhängen. Ich habe einen dynamischen PDF- und Bildpfad, der in einer quote_item
Tabelle gespeichert ist . Ich habe Code debuggt, um Bild / PDF anzuhängen und E-Mail zu bestellen.
<preference for="Magento\Framework\Mail\Template\TransportBuilder" type="vendor\moduleName\Model\Mail\MailTransportBuilder"></preference>
<preference for="Magento\Sales\Model\Order\Email\SenderBuilder" type="vendor\moduleName\Model\Mail\SenderBuilder"/>
<?php
namespace vendor\moduleName\Model\Mail;
class MailTransportBuilder extends \Magento\Framework\Mail\Template\TransportBuilder
{
public function addPdfAttachment($fileContent, $filename)
{
if ($fileContent) {
$this->message->createAttachment(
$fileContent,
'application/pdf',
\Zend_Mime::DISPOSITION_ATTACHMENT,
\Zend_Mime::ENCODING_BASE64,
$filename
);
return $this;
}
}
public function addImageAttachment($fileContent, $filename)
{
if ($fileContent) {
$this->message->createAttachment(
$fileContent,
\Zend_Mime::TYPE_OCTETSTREAM,
\Zend_Mime::DISPOSITION_ATTACHMENT,
\Zend_Mime::ENCODING_BASE64,
$filename
);
return $this;
}
}
}
<?php
/**
* @author Kristof Ringleff
* @package Fooman_EmailAttachments
* @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz)
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace vendor\moduleName\Model\Mail;
use Magento\Framework\Mail\Template\TransportBuilder;
use Magento\Sales\Model\Order\Email\Container\IdentityInterface;
use Magento\Sales\Model\Order\Email\Container\Template;
class SenderBuilder extends \Magento\Sales\Model\Order\Email\SenderBuilder
{
/**
* @var Template
*/
protected $templateContainer;
/**
* @var IdentityInterface
*/
protected $identityContainer;
/**
* @var TransportBuilder
*/
protected $transportBuilder;
/**
* @param Template $templateContainer
* @param IdentityInterface $identityContainer
* @param TransportBuilder $transportBuilder
*/
public function __construct(
Template $templateContainer,
IdentityInterface $identityContainer,
TransportBuilder $transportBuilder
) {
$this->templateContainer = $templateContainer;
$this->identityContainer = $identityContainer;
$this->transportBuilder = $transportBuilder;
}
/**
* Prepare and send email message
*
* @return void
*/
public function send()
{
$this->transportBuilder->addPdfAttachment(file_get_contents($data),$data);
parent::send();
}
}
Wie kann ich ein Auftragsobjekt in die SenderBuilder-Klasse einfügen?