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
AddEventTicketsToDonationConfirmationPageDonationTotal.php
42 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\EventTickets\Actions; |
| 4 | |
| 5 | use Give\EventTickets\Models\EventTicket; |
| 6 | use Give\EventTickets\Repositories\EventTicketRepository; |
| 7 | use Give\Framework\Receipts\DonationReceipt; |
| 8 | use Give\Framework\Receipts\Properties\ReceiptDetail; |
| 9 | use Give\Framework\Support\ValueObjects\Money; |
| 10 | |
| 11 | /** |
| 12 | * @since 3.6.0 |
| 13 | */ |
| 14 | class AddEventTicketsToDonationConfirmationPageDonationTotal |
| 15 | { |
| 16 | /** |
| 17 | * @since 3.6.0 |
| 18 | */ |
| 19 | public function __invoke(DonationReceipt $receipt): void |
| 20 | { |
| 21 | $eventTickets = give(EventTicketRepository::class)->queryByDonationId($receipt->donation->id)->getAll(); |
| 22 | |
| 23 | if (!empty($eventTickets)) { |
| 24 | $currency = $receipt->donation->amount->getCurrency(); |
| 25 | $total = array_reduce($eventTickets, function (Money $carry, EventTicket $eventTicket) { |
| 26 | $ticketType = $eventTicket->ticketType()->get(); |
| 27 | |
| 28 | return $carry->add( |
| 29 | $ticketType->price |
| 30 | ); |
| 31 | }, new Money(0, $currency)); |
| 32 | |
| 33 | $receipt->donationDetails->addDetail( |
| 34 | new ReceiptDetail( |
| 35 | __('Event Tickets', 'give'), |
| 36 | $total->formatToLocale() |
| 37 | ) |
| 38 | ); |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 |