Skip to content

Commit

Permalink
Merge pull request #27237 from seamuslee001/dev_core_4537
Browse files Browse the repository at this point in the history
dev/core#4537 Ensure that Event Registration email works when CiviCon…
  • Loading branch information
seamuslee001 authored Sep 1, 2023
2 parents 7e21230 + cf45130 commit 0f7ea0f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 30 deletions.
62 changes: 34 additions & 28 deletions CRM/Event/WorkflowMessage/ParticipantTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ trait CRM_Event_WorkflowMessage_ParticipantTrait {
*/
protected $participantContacts;

private function isCiviContributeEnabled(): bool {
return array_key_exists('Contribution', \Civi::service('action_object_provider')->getEntities());
}

/**
* @param array $participantContacts
*
Expand All @@ -93,7 +97,7 @@ public function setEventID(int $eventID): self {
*/
public function setParticipantID(int $participantID) {
$this->participantID = $participantID;
if (!$this->getContributionID()) {
if (!$this->getContributionID() && $this->isCiviContributeEnabled()) {
$lineItem = LineItem::get(FALSE)
->addWhere('entity_table', '=', 'civicrm_participant')
->addWhere('entity_id', '=', $participantID)
Expand Down Expand Up @@ -186,34 +190,36 @@ public function getParticipants(): array {
}
// Initiate with the current participant to ensure they are first.
$participants = [$this->participantID => ['id' => $this->participantID, 'tax_rate_breakdown' => []]];
foreach ($this->getLineItems() as $lineItem) {
if ($lineItem['entity_table'] === 'civicrm_participant') {
$participantID = $lineItem['entity_id'];
}
else {
// It is not clear if this could ever be true - testing the CiviCRM event
// form shows all line items assigned to participants but we should
// assign to primary if this can occur.
$participantID = $this->getPrimaryParticipantID();
}
$participants[$participantID]['line_items'][] = $lineItem;
if (!isset($participants[$participantID]['totals'])) {
$participants[$participantID]['totals'] = ['total_amount_exclusive' => 0, 'tax_amount' => 0, 'total_amount_inclusive' => 0];
}
$participants[$participantID]['totals']['total_amount_exclusive'] += $lineItem['line_total'];
$participants[$participantID]['totals']['tax_amount'] += $lineItem['tax_amount'];
$participants[$participantID]['totals']['total_amount_inclusive'] += ($lineItem['line_total'] + $lineItem['tax_amount']);
if (!isset($participants[$participantID]['tax_rate_breakdown'])) {
$participants[$participantID]['tax_rate_breakdown'] = [];
}
if (!isset($participants[$participantID]['tax_rate_breakdown'][$lineItem['tax_rate']])) {
$participants[$participantID]['tax_rate_breakdown'][$lineItem['tax_rate']] = [
'amount' => 0,
'rate' => $lineItem['tax_rate'],
'percentage' => sprintf('%.2f', $lineItem['tax_rate']),
];
if ($this->isCiviContributeEnabled()) {
foreach ($this->getLineItems() as $lineItem) {
if ($lineItem['entity_table'] === 'civicrm_participant') {
$participantID = $lineItem['entity_id'];
}
else {
// It is not clear if this could ever be true - testing the CiviCRM event
// form shows all line items assigned to participants but we should
// assign to primary if this can occur.
$participantID = $this->getPrimaryParticipantID();
}
$participants[$participantID]['line_items'][] = $lineItem;
if (!isset($participants[$participantID]['totals'])) {
$participants[$participantID]['totals'] = ['total_amount_exclusive' => 0, 'tax_amount' => 0, 'total_amount_inclusive' => 0];
}
$participants[$participantID]['totals']['total_amount_exclusive'] += $lineItem['line_total'];
$participants[$participantID]['totals']['tax_amount'] += $lineItem['tax_amount'];
$participants[$participantID]['totals']['total_amount_inclusive'] += ($lineItem['line_total'] + $lineItem['tax_amount']);
if (!isset($participants[$participantID]['tax_rate_breakdown'])) {
$participants[$participantID]['tax_rate_breakdown'] = [];
}
if (!isset($participants[$participantID]['tax_rate_breakdown'][$lineItem['tax_rate']])) {
$participants[$participantID]['tax_rate_breakdown'][$lineItem['tax_rate']] = [
'amount' => 0,
'rate' => $lineItem['tax_rate'],
'percentage' => sprintf('%.2f', $lineItem['tax_rate']),
];
}
$participants[$participantID]['tax_rate_breakdown'][$lineItem['tax_rate']]['amount'] += $lineItem['tax_amount'];
}
$participants[$participantID]['tax_rate_breakdown'][$lineItem['tax_rate']]['amount'] += $lineItem['tax_amount'];
}

$count = 1;
Expand Down
2 changes: 1 addition & 1 deletion Civi/Test/EventTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function eventCreatePaid(array $eventParameters = [], array $priceSetP
}

/**
* Create a paid event.
* Create an unpaid event.
*
* @param array $eventParameters
* Values to
Expand Down
7 changes: 6 additions & 1 deletion Civi/Token/TokenCompatSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ public function setupSmartyAliases(TokenValueEvent $e) {
*/
public function onRender(TokenRenderEvent $e): void {
$useSmarty = !empty($e->context['smarty']);
$e->string = $e->getTokenProcessor()->visitTokens($e->string, function() {
$e->string = $e->getTokenProcessor()->visitTokens($e->string, function($token = NULL, $entity = NULL, $field = NULL, $filterParams = NULL) {
if ($filterParams && $filterParams[0] === 'boolean') {
// This token was missed during primary rendering, and it's supposed to be coerced to boolean.
// Treat an unknown token as false-y.
return 0;
}
// For historical consistency, we filter out unrecognized tokens.
return '';
});
Expand Down
33 changes: 33 additions & 0 deletions tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,4 +721,37 @@ protected function submitPaidEvent(array $submitValues = []): void {
], $submitValues));
}

public function testRegistrationWithoutCiviContributeEnabled(): void {
$mut = new CiviMailUtils($this, TRUE);
$event = $this->eventCreateUnpaid([
'has_waitlist' => 1,
'max_participants' => 1,
'start_date' => 20351021,
'end_date' => 20351023,
'registration_end_date' => 20351015,
]);
CRM_Core_BAO_ConfigSetting::disableComponent('CiviContribute');
$this->submitForm(
$event['id'], [
[
'first_name' => 'Bruce No Contribute',
'last_name' => 'Wayne',
'email-Primary' => 'bruce@gotham.com',
'is_primary' => 1,
'is_pay_later' => 0,
'campaign_id' => NULL,
'defaultRole' => 1,
'participant_role_id' => '1',
'button' => '_qf_Register_upload',
],
]
);
$mut->checkMailLog([
'Dear Bruce No Contribute, Thank you for your registration. This is a confirmation that your registration has been received and your status has been updated to Registered.',
]);
$mut->stop();
$mut->clearMessages();
CRM_Core_BAO_ConfigSetting::enableComponent('CiviContribute');
}

}

0 comments on commit 0f7ea0f

Please sign in to comment.