59 lines
2.0 KiB
PHP
59 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Stemcell\Sales\Model\Order\Email;
|
|
|
|
use Magento\Framework\Exception\LocalizedException;
|
|
use Magento\Framework\Exception\MailException;
|
|
use Stemcell\Sales\Model\Order\Template\TransportBuilder;
|
|
use Magento\Framework\Mail\Template\TransportBuilderByStore;
|
|
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
|
|
{
|
|
protected string $filePath;
|
|
|
|
public function __construct(Template $templateContainer, IdentityInterface $identityContainer, TransportBuilder $transportBuilder, TransportBuilderByStore $transportBuilderByStore = null)
|
|
{
|
|
parent::__construct($templateContainer, $identityContainer, $transportBuilder, $transportBuilderByStore);
|
|
}
|
|
|
|
/**
|
|
* @throws MailException
|
|
* @throws LocalizedException
|
|
*/
|
|
public function send()
|
|
{
|
|
$this->configureEmailTemplate();
|
|
$copyTo = $this->identityContainer->getEmailCopyTo();
|
|
$this->transportBuilder->addTo(
|
|
$this->identityContainer->getCustomerEmail(),
|
|
$this->identityContainer->getCustomerName()
|
|
);
|
|
|
|
if (!empty($copyTo)) {
|
|
$this->transportBuilder->addTo($copyTo);
|
|
$this->transportBuilder->setMessageData('to', $copyTo);
|
|
}
|
|
if (isset($this->filePath)) {
|
|
$attachmentMime = [
|
|
'type' => 'application/vnd.ms-excel',
|
|
'content' => $this->filePath,
|
|
'disposition' => \Laminas\Mime\Mime::DISPOSITION_ATTACHMENT,
|
|
'encoding' => \Laminas\Mime\Mime::ENCODING_BASE64,
|
|
'fileName' => 'order.xlsx'
|
|
];
|
|
$this->transportBuilder->setAttachmentMimePart($attachmentMime);
|
|
}
|
|
|
|
$transport = $this->transportBuilder->getTransport();
|
|
$transport->sendMessage();
|
|
}
|
|
|
|
public function setAttachmentFile(string $filePath): static
|
|
{
|
|
$this->filePath = $filePath;
|
|
return $this;
|
|
}
|
|
}
|