Allow multiple billets in invitation form, dynamic add/remove lines
- Form sends items[] array with billet_id and quantity per line - JS button to add more billet lines with remove button - Controller iterates over items to create multiple BilletBuyerItems - Same flow: all tickets generated with isInvitation=true Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -712,20 +712,14 @@ class AccountController extends AbstractController
|
||||
$firstName = trim($request->request->getString('first_name'));
|
||||
$lastName = trim($request->request->getString('last_name'));
|
||||
$email = trim($request->request->getString('email'));
|
||||
$billetId = $request->request->getInt('billet_id');
|
||||
$quantity = $request->request->getInt('quantity', 1);
|
||||
$items = $request->request->all('items');
|
||||
|
||||
if ('' === $firstName || '' === $lastName || '' === $email || 0 === $billetId) {
|
||||
if ('' === $firstName || '' === $lastName || '' === $email || 0 === \count($items)) {
|
||||
$this->addFlash('error', 'Tous les champs sont requis.');
|
||||
|
||||
return $this->redirectToRoute('app_account_edit_event', ['id' => $event->getId(), 'tab' => 'invitations']);
|
||||
}
|
||||
|
||||
$billet = $em->getRepository(Billet::class)->find($billetId);
|
||||
if (!$billet || $billet->getCategory()->getEvent()->getId() !== $event->getId()) {
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
$count = $em->getRepository(BilletBuyer::class)->count([]) + 1;
|
||||
|
||||
$order = new BilletBuyer();
|
||||
@@ -736,12 +730,28 @@ class AccountController extends AbstractController
|
||||
$order->setOrderNumber(date('Y-m-d').'-'.$count);
|
||||
$order->setTotalHT(0);
|
||||
|
||||
$item = new BilletBuyerItem();
|
||||
$item->setBillet($billet);
|
||||
$item->setBilletName($billet->getName());
|
||||
$item->setQuantity($quantity);
|
||||
$item->setUnitPriceHT(0);
|
||||
$order->addItem($item);
|
||||
foreach ($items as $itemData) {
|
||||
$billetId = (int) ($itemData['billet_id'] ?? 0);
|
||||
$qty = max(1, (int) ($itemData['quantity'] ?? 1));
|
||||
|
||||
$billet = $em->getRepository(Billet::class)->find($billetId);
|
||||
if (!$billet || $billet->getCategory()->getEvent()->getId() !== $event->getId()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$item = new BilletBuyerItem();
|
||||
$item->setBillet($billet);
|
||||
$item->setBilletName($billet->getName());
|
||||
$item->setQuantity($qty);
|
||||
$item->setUnitPriceHT(0);
|
||||
$order->addItem($item);
|
||||
}
|
||||
|
||||
if ($order->getItems()->isEmpty()) {
|
||||
$this->addFlash('error', 'Aucun billet valide selectionne.');
|
||||
|
||||
return $this->redirectToRoute('app_account_edit_event', ['id' => $event->getId(), 'tab' => 'invitations']);
|
||||
}
|
||||
|
||||
$em->persist($order);
|
||||
$em->flush();
|
||||
|
||||
Reference in New Issue
Block a user