Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflow template for offline event #22904

Merged
merged 1 commit into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,6 @@ public function submit($params) {
}
}
}
$this->assign('totalTaxAmount', $totalTaxAmount);
$this->assign('taxTerm', $this->getSalesTaxTerm());
$this->assign('dataArray', $dataArray);
}
Expand All @@ -1516,13 +1515,16 @@ public function submit($params) {
$eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
$this->assign('amount', $eventAmount);
}

$this->assign('totalTaxAmount', $totalTaxAmount ?? 0);
$sendTemplateParams = [
'groupName' => 'msg_tpl_workflow_event',
'valueName' => 'event_offline_receipt',
'workflow' => 'event_offline_receipt',
'contactId' => $contactID,
'isTest' => !empty($this->_defaultValues['is_test']),
'PDFFilename' => ts('confirmation') . '.pdf',
'modelProps' => [
'participantID' => $this->_id,
'eventID' => $params['event_id'],
],
];

// try to send emails only if email id is present
Expand Down
8 changes: 5 additions & 3 deletions CRM/Event/Form/ParticipantFeeSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,16 @@ public function emailReceipt(&$params) {
$this->assign('isOnWaitlist', TRUE);
}
$this->assign('contactID', $this->_contactId);
$this->assign('participantID', $this->_participantId);

$sendTemplateParams = [
'groupName' => 'msg_tpl_workflow_event',
'valueName' => 'event_offline_receipt',
'workflow' => 'event_offline_receipt',
'contactId' => $this->_contactId,
'isTest' => FALSE,
'PDFFilename' => ts('confirmation') . '.pdf',
'modelProps' => [
'participantID' => $this->_participantId,
'eventID' => $params['event_id'],
],
];

// try to send emails only if email id is present
Expand Down
4 changes: 3 additions & 1 deletion CRM/Event/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,12 @@ protected function getEventTokenValues(int $eventID = NULL): array {
*
*/
protected function getExposedFields(): array {
return ['event_type_id',
return [
'event_type_id',
'title',
'id',
'event_tz',
'pay_later_receipt',
'start_date',
'end_date',
'summary',
Expand Down
26 changes: 26 additions & 0 deletions CRM/Event/WorkflowMessage/EventOfflineReceipt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

use Civi\WorkflowMessage\GenericWorkflowMessage;

/**
* Receipt sent when confirming a back office participation record.
*
* @support template-only
*
* @see CRM_Event_Form_Participant::submit()
* @see CRM_Event_Form_ParticipantFeeSelection::emailReceipt
*/
class CRM_Event_WorkflowMessage_EventOfflineReceipt extends GenericWorkflowMessage {
use CRM_Event_WorkflowMessage_ParticipantTrait;
public const WORKFLOW = 'event_offline_receipt';

}
11 changes: 9 additions & 2 deletions CRM/Event/WorkflowMessage/ParticipantTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ trait CRM_Event_WorkflowMessage_ParticipantTrait {
/**
* @var int
*
* @scope tokenContext as participantId
* @scope tokenContext as participantId, tplParams as participantID
*/
public $participantId;
public $participantID;

/**
* @var int
*
* @scope tokenContext as eventId, tplParams as eventID
*/
public $eventID;

}
27 changes: 17 additions & 10 deletions tests/phpunit/CRM/Event/Form/ParticipantTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Civi\Api4\Participant;

/**
* Test CRM_Event_Form_Registration functions.
*
Expand All @@ -21,19 +23,12 @@ public function setUp(): void {
parent::setUp();
}

/**
* Should financials be checked after the test but before tear down.
*
* @var bool
*/
protected $isValidateFinancialsOnPostAssert = TRUE;

/**
* Initial test of submit function.
*
* @throws \Exception
*/
public function testSubmit() {
public function testSubmit(): void {
$form = $this->getForm();
$form->submit([
'register_date' => date('Ymd'),
Expand Down Expand Up @@ -262,8 +257,9 @@ public function testSubmitWithFailedPayment($thousandSeparator, $fromEmails = []
* @dataProvider getThousandSeparators
* @throws \Exception
*/
public function testParticipantOfflineReceipt($thousandSeparator) {
public function testParticipantOfflineReceipt(string $thousandSeparator): void {
$this->setCurrencySeparators($thousandSeparator);
$this->swapMessageTemplateForTestTemplate('event_offline_receipt', 'text');
$mut = new CiviMailUtils($this, TRUE);
// Create an email associated with the logged in contact
$loggedInContactID = $this->createLoggedInUser();
Expand Down Expand Up @@ -298,7 +294,7 @@ public function testParticipantOfflineReceipt($thousandSeparator) {

// Use the email created as the from email ensuring we are passing a numeric from to test dev/core#1069
$this->setCurrencySeparators($thousandSeparator);
$form = $this->getForm(['is_monetary' => 1, 'financial_type_id' => 1]);
$form = $this->getForm(['is_monetary' => 1, 'financial_type_id' => 1, 'pay_later_receipt' => 'pay us']);
$form->_mode = 'Live';
$form->_quickConfig = TRUE;
$form->_fromEmails = [
Expand All @@ -308,13 +304,24 @@ public function testParticipantOfflineReceipt($thousandSeparator) {
$submitParams = $this->getSubmitParamsForCreditCardPayment($paymentProcessorID);
$submitParams['from_email_address'] = $email['id'];
$form->submit($submitParams);
$participantID = Participant::get()->addWhere('event_id', '=', $this->getEventID())->execute()->first()['id'];
//Check if type is correctly populated in mails.
//Also check the string email is present not numeric from.
$mut->checkMailLog([
'contactID:::' . $this->getContactID(),
'contact.id:::' . $this->getContactID(),
'eventID:::' . $this->getEventID(),
'event.id:::' . $this->getEventID(),
'participantID:::' . $participantID,
'participant.id:::' . $participantID,
'<p>Test event type - 1</p>',
'event.title:::Annual CiviCRM meet',
'participant.status_id:name:::Registered',
'testloggedinreceiptemail@civicrm.org',
'event.pay_later_receipt:::pay us',
$this->formatMoneyInput(1550.55),
]);

$this->callAPISuccess('Email', 'delete', ['id' => $email['id']]);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/CRM/Utils/TokenConsistencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ protected function getExpectedEventTokenOutput(): string {

event.info_url :' . CRM_Utils_System::url('civicrm/event/info', NULL, TRUE) . '&reset=1&id=1
event.registration_url :' . CRM_Utils_System::url('civicrm/event/register', NULL, TRUE) . '&reset=1&id=1
event.pay_later_receipt :
event.custom_1 :my field
';
}
Expand Down Expand Up @@ -904,6 +905,7 @@ protected function getEventTokens(): array {
'{event.location}' => 'Event Location',
'{event.info_url}' => 'Event Info URL',
'{event.registration_url}' => 'Event Registration URL',
'{event.pay_later_receipt}' => 'Pay Later Receipt Text',
'{event.' . $this->getCustomFieldName('text') . '}' => 'Enter text here :: Group with field text',
];
}
Expand Down
10 changes: 10 additions & 0 deletions tests/templates/message_templates/event_offline_receipt_text.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
contactID:::{$contactID}
eventID:::{$eventID}
participantID:::{$participantID}
contact.id:::{contact.id}
event.id:::{event.id}
participant.id:::{participant.id}
event.title:::{event.title}
participant.status_id:name:::{participant.status_id:name}
email:::{$email}
event.pay_later_receipt:::{event.pay_later_receipt}