fix tickets getting cut in order pdf
All checks were successful
build / build (pull_request) Successful in 47s

This commit is contained in:
2025-02-28 23:39:37 +01:00
parent b98bc363d5
commit 45a9320d22

View File

@ -12,6 +12,7 @@ use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Part\DataPart;
use Symfony\Component\VarDumper\Cloner\Data;
use Twig\Environment;
class TicketEmailService
@ -33,14 +34,25 @@ class TicketEmailService
->to(new Address($payment->getCustomer()?->getEmail(), $payment->getCustomer()?->getFirstname() . ' ' . $payment->getCustomer()?->getLastname()))
->context([
'payment' => $payment,
])
->addPart(new DataPart($this->generateTicket($payment->getCustomer()?->getTickets()), 'tickets.pdf', 'application/pdf'));
]);
$acc = 0;
foreach ($this->generateTicket($payment->getCustomer()?->getTickets()) as $pdf) {
$mail->attach($pdf, 'tickets-'.++$acc.'.pdf', 'application/pdf');
}
$this->mailer->send($mail);
}
private function generateTicket(Collection $tickets): string
private function generateTicket(Collection $tickets): array
{
return (new DompdfWrapper(new DompdfFactory()))->getPdf($this->twig->render('email/pdf.html.twig', ['tickets' => $tickets]));
$ticketChunks = array_chunk($tickets->toArray(), 3);
$pdfs = [];
foreach ($ticketChunks as $ticket) {
$pdfs[] = (new DompdfWrapper(new DompdfFactory()))->getPdf($this->twig->render('email/pdf.html.twig', ['tickets' => $ticket]));
}
return $pdfs;
}
}