give
/
src
/
EventTickets
/
Actions
/
AddEventTicketsToDonationConfirmationPageEventTicketDetails.php
AddEventTicketsToDonationConfirmationPageDonationTotal.php
2 years ago
AddEventTicketsToDonationConfirmationPageEventTicketDetails.php
2 years ago
AttachAttendeeDataToTicketData.php
2 years ago
ConvertEventTicketsBlockToFieldsApi.php
2 years ago
EnqueueDonationFormScripts.php
2 years ago
EnqueueEventDetailsScripts.php
2 years ago
EnqueueFormBuilderScripts.php
2 years ago
EnqueueListTableScripts.php
2 years ago
GenerateTicketsFromPurchaseData.php
2 years ago
RegisterEventsMenuItem.php
2 years ago
RenderDonationFormBlock.php
2 years ago
UpdateDonationConfirmationPageReceiptDonationAmount.php
2 years ago
AddEventTicketsToDonationConfirmationPageEventTicketDetails.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\EventTickets\Actions; |
| 4 | |
| 5 | use Give\EventTickets\Repositories\EventTicketRepository; |
| 6 | use Give\Framework\Receipts\DonationReceipt; |
| 7 | use Give\Framework\Receipts\Properties\ReceiptDetail; |
| 8 | |
| 9 | /** |
| 10 | * @since 3.6.0 |
| 11 | */ |
| 12 | class AddEventTicketsToDonationConfirmationPageEventTicketDetails |
| 13 | { |
| 14 | /** |
| 15 | * @since 3.6.0 |
| 16 | */ |
| 17 | public function __invoke(DonationReceipt $receipt): void |
| 18 | { |
| 19 | $eventTickets = give(EventTicketRepository::class)->queryByDonationId($receipt->donation->id)->getAll(); |
| 20 | |
| 21 | if (empty($eventTickets)) { |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | $event = $eventTickets[0]->event()->get(); |
| 26 | $ticketTypes = []; |
| 27 | |
| 28 | foreach ($eventTickets as $eventTicket) { |
| 29 | $ticketType = $eventTicket->ticketType()->get(); |
| 30 | $ticketTypeId = $ticketType->id; |
| 31 | |
| 32 | if (isset($ticketTypes[$ticketTypeId])) { |
| 33 | $ticketTypes[$ticketTypeId]['quantity'] += 1; |
| 34 | } else { |
| 35 | $ticketTypes[$ticketTypeId] = [ |
| 36 | 'title' => $ticketType->title, |
| 37 | 'quantity' => 1, |
| 38 | ]; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | foreach ($ticketTypes as $ticketType) { |
| 43 | $detailString = sprintf(__('%s - %s', 'give'), $event->title, $ticketType['title']); |
| 44 | $receipt->eventTicketsDetails->addDetail(new ReceiptDetail($detailString, $ticketType['quantity'])); |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 |