Skip to content

Commit

Permalink
Fix transfer registration to transfer participant_payment row
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jul 7, 2021
1 parent cf2aa24 commit 67747ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
12 changes: 9 additions & 3 deletions CRM/Event/Form/SelfSvcTransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";
Expand Down
15 changes: 10 additions & 5 deletions tests/phpunit/CRM/Event/Form/ParticipantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase {

use CRMTraits_Financial_OrderTrait;
/**
* Options on the from Email address array.
*
Expand Down Expand Up @@ -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');
Expand All @@ -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);

}

/**
Expand Down

0 comments on commit 67747ed

Please sign in to comment.