From 67747edb6325f02e7b1eb5ef097ef25a4a31e91d Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 19 Jun 2021 15:22:55 +1200 Subject: [PATCH] Fix transfer registration to transfer participant_payment row --- CRM/Event/Form/SelfSvcTransfer.php | 12 +++++++++--- tests/phpunit/CRM/Event/Form/ParticipantTest.php | 15 ++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CRM/Event/Form/SelfSvcTransfer.php b/CRM/Event/Form/SelfSvcTransfer.php index 1d5ac36d7210..586a7b226253 100644 --- a/CRM/Event/Form/SelfSvcTransfer.php +++ b/CRM/Event/Form/SelfSvcTransfer.php @@ -513,14 +513,19 @@ public function transferParticipantRegistration($toContactID, $fromParticipantID ->addWhere('id', '=', $fromParticipantID) ->execute() ->first(); - + $participantPayments = civicrm_api3('ParticipantPayment', 'get', [ + 'return' => 'id', + 'participant_id' => $fromParticipantID, + ])['values']; unset($toParticipantValues['id']); $toParticipantValues['contact_id'] = $toContactID; $toParticipantValues['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Event_BAO_Participant', 'status_id', 'Registered'); $toParticipantValues['register_date'] = date("Y-m-d"); //first create the new participant row -don't set registered_by yet or email won't be sent $participant = CRM_Event_BAO_Participant::create($toParticipantValues); - + foreach ($participantPayments as $payment) { + civicrm_api3('ParticipantPayment', 'create', ['id' => $payment['id'], 'participant_id' => $participant->id]); + } //send a confirmation email to the new participant $this->participantTransfer($participant); //now update registered_by_id @@ -531,7 +536,8 @@ public function transferParticipantRegistration($toContactID, $fromParticipantID $line_items = CRM_Price_BAO_LineItem::getLineItems($fromParticipantID); foreach ($line_items as $id => $item) { //Remove contribution id from older participant line item. - CRM_Core_DAO::singleValueQuery("UPDATE civicrm_line_item SET contribution_id = NULL WHERE id = %1", [1 => [$id, 'Integer']]); + CRM_Core_DAO::singleValueQuery('UPDATE civicrm_line_item SET contribution_id = NULL WHERE id = %1', [1 => [$id, 'Integer']]); + $item['entity_id'] = $participant->id; $item['id'] = NULL; $item['entity_table'] = "civicrm_participant"; diff --git a/tests/phpunit/CRM/Event/Form/ParticipantTest.php b/tests/phpunit/CRM/Event/Form/ParticipantTest.php index bac093c80804..8ebab8d9ef5d 100644 --- a/tests/phpunit/CRM/Event/Form/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/Form/ParticipantTest.php @@ -8,6 +8,7 @@ */ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { + use CRMTraits_Financial_OrderTrait; /** * Options on the from Email address array. * @@ -824,13 +825,13 @@ protected function getRecordContributionParams($participantStatus, $contribution * @throws \CRM_Core_Exception * @throws \CiviCRM_API3_Exception */ - public function testTransferParticipantRegistration() { + public function testTransferParticipantRegistration(): void { //Register a contact to a sample event. - $this->createParticipantRecordsFromTwoFieldPriceSet(); - $contribution = $this->callAPISuccessGetSingle('Contribution', []); + $this->createEventOrder(); + $contribution = $this->callAPISuccessGetSingle('Contribution', ['return' => 'id']); //Check line item count of the contribution id before transfer. $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribution['id']); - $this->assertEquals(count($lineItems), 2); + $this->assertCount(2, $lineItems); $participantId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $contribution['id'], 'participant_id', 'contribution_id'); /* @var CRM_Event_Form_SelfSvcTransfer $form */ $form = $this->getFormObject('CRM_Event_Form_SelfSvcTransfer'); @@ -852,7 +853,11 @@ public function testTransferParticipantRegistration() { //Check line item count of the contribution id remains the same. $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribution['id']); - $this->assertEquals(count($lineItems), 2); + $this->assertCount(2, $lineItems); + // There should be 2 participant payments on the contribution & 0 others existing. + $this->callAPISuccessGetCount('ParticipantPayment', ['contribution_id' => $contribution['id']], 2); + $this->callAPISuccessGetCount('ParticipantPayment', [], 2); + } /**