Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fix no additional participant information in paid event confirmation emails
/**
* Implements hook_civicrm_alterMailParams().
*/
function cudar_civicrm_alterMailParams(&$params, $context) {
/*
* Redirection from payment gateway which trigger default event confirmation email is missing additional participants information and participants profiles. This is fix.
*/
if (isset($params['groupName']) && $params['groupName'] == 'msg_tpl_workflow_event' && $params['valueName'] == 'event_online_receipt' && empty($params['tplParams']['part'] && !empty($params['tplParams']['lineItem']))) {
//set variable that email is no test and shoudl look like live email
$params['isTest'] = 0;
$primiaryParticipantId = $params['tplParams']['participantID'];
$primiaryContactId = $params['tplParams']['participant'][$primiaryParticipantId]['contact_id'];
//loop via lineItems and load additional participants
foreach ($params['tplParams']['lineItem'] as $k => $v) {
foreach ($v as $participantData) {
$result = cudar_civi_api('Participant', 'getsingle', array(
'id' => $participantData['entity_id'],
));
$params['tplParams']['part'][$k]['info'] = $result['display_name'];
if ($participantData['entity_id'] == $primiaryParticipantId) {
$params['tplParams']['isPrimary'] = 1;
}
}
}
//load additional profiles assigned to event
$additionalParticipantProfile = civicrm_api3('UFJoin', 'get', array(
'return' => array('uf_group_id.id', 'module'),
'entity_id' => $params['tplParams']['event']['id'],
'module' => 'CiviEvent_Additional',
));
//build main participant profile
$template = CRM_Core_Smarty::singleton();
$preProfileID = CRM_Utils_Array::value('custom_pre_id', $params['tplParams']);
$postProfileID = CRM_Utils_Array::value('custom_post_id', $params['tplParams']);
if ($preProfileID) {
CRM_Event_BAO_Event::buildCustomDisplay($preProfileID, 'customPre', $primiaryContactId, $template, $primiaryParticipantId, FALSE
);
}
if ($postProfileID) {
CRM_Event_BAO_Event::buildCustomDisplay($postProfileID, 'customPost', $primiaryContactId, $template, $primiaryParticipantId, FALSE
);
}
//build addtional custom profile
if (!$additionalParticipantProfile['is_error'] && !empty($additionalParticipantProfile['values'])) {
foreach ($additionalParticipantProfile['values'] as $profileId => $profileData) {
$params['tplParams']['additional_custom_pre_id'][$profileId] = $profileData['uf_group_id.id'];
}
$customProfile = CRM_Event_BAO_Event::buildCustomProfile($primiaryParticipantId, $params['tplParams'], $primiaryContactId);
if (count($customProfile)) {
$params['tplParams']['customProfile'] = $customProfile;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment