SuperSeller3000/src/Infrastructure/Mail/SymfonyInvoiceMailer.php

56 lines
1.7 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace App\Infrastructure\Mail;
use App\Application\Order\InvoiceMailerInterface;
use App\Domain\Order\Invoice;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
final class SymfonyInvoiceMailer implements InvoiceMailerInterface
{
public function __construct(
private readonly MailerInterface $mailer,
private readonly string $supplierEmail,
private readonly string $senderEmail,
) {
}
public function sendInvoice(Invoice $invoice): void
{
$order = $invoice->getOrder();
$article = $order->getArticle();
$customer = $order->getCustomer();
$body = \sprintf(
"Neue Bestellung eingegangen — bitte sofort versenden.\n\n"
."Bestellnummer : %s\n"
."Artikel : %s\n"
."Inventarnummer: %s\n"
."Käufer : %s\n"
."Verkaufspreis : €%s\n\n"
.'Die Rechnung liegt diesem E-Mail als PDF bei.',
$order->getPlatformOrderId(),
$article->getEbayTitle() ?? $article->getSku(),
$article->getInventoryNumber(),
$customer->getName(),
$order->getSalePrice(),
);
$email = (new Email())
->from($this->senderEmail)
->to($this->supplierEmail)
->subject('Neue Bestellung: '.$order->getPlatformOrderId())
->text($body)
->attachFromPath(
$invoice->getFullPath(),
'Rechnung-'.$invoice->getFrappeInvoiceId().'.pdf',
'application/pdf',
);
$this->mailer->send($email);
}
}