CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Won't converted custom tokens in email
Pages: [1]

Author Topic: Won't converted custom tokens in email  (Read 549 times)

megabait

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
  • CiviCRM version: 4.6.6
  • CMS version: WordPress 4.2.4
  • MySQL version: MySQL 5.6
  • PHP version: PHP 5.5
Won't converted custom tokens in email
August 18, 2015, 11:24:04 am
Hello, I created custom extension to extend CiviEvent and in there created email tokens but tokens doesn't work, what I mean if I add them to "Events - Registration Confirmation and Receipt" template they appear in Tokens dropdown and I can add to the page, but when I get email they doesn't converted for ex. part of email "Dear Ivan Petrom,

{contact.participant_id}{contact.barcode} Thank you for your participation. This letter is a confirmation that your registration has been received and your status has been updated toRegistered.

Please print this confirmation for your records.". But if I send email using "Send email to contact" all tokens converted and working fine.

Php code which I am using for custom tokens

   
Code: [Select]
function tickets_civicrm_tokens(&$tokens) {
    $tokens['contact'] = array(
        'contact.participant_id' => 'Participant id',
        'contact.event_id' => 'Event id',
        'contact.register_date' => 'Register date',
        'contact.barcode' => 'Barcode Path'
    );
}

function tickets_civicrm_tokenValues(&$values, $cids, $job = null, $tokens = array(), $context = null) {
    $barcode_path = civicrm_api3('setting', 'getValue', array('name' => 'extensionsURL'));
    foreach ($cids as $cid) {
        $apiParams = array(
            'version' => 3,
            'contact_id' => $cid
        );
        $result = civicrm_api('Participant', 'Get', $apiParams);
        if (!$result['is_error']) {
            $contact_info = reset($result['values']);
            $values[$cid]['contact.participant_id'] = $contact_info['participant_id'];
            $values[$cid]['contact.event_id'] = $contact_info['event_id'];
            $values[$cid]['contact.register_date'] = date('YmdHis', strtotime($contact_info['participant_register_date']));
            $values[$cid]['contact.barcode'] = $barcode_path . 'com.example.tickets/barcodegen/html/';
        }
    }
}
Or how to add custom data to email template in backend? Thank you

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Won't converted custom tokens in email
August 19, 2015, 12:31:03 am
I don't have very deep experience with the event registration code, but -- using grep -- turned up some leads.

Grepping on the phrase "Events - Registration Confirmation and Receipt", it appears that this associated with two message templates, "event_offline_receipt" and "event_online_receipt".

Grepping further on those, there are a couple places which send out the messages. The first one I looked at was CRM_Event_Form_Participant::postProcess(), which constructs $sendTemplateParams and passes them to CRM_Core_BAO_MessageTemplate::sendTemplate().

Inspecting sendTemplate(), it only includes tokens if $params provides a contactId. From skimming, it doesn't look the contactId is provided in this case. (But to verify, you'd have to reproduce the problem and use a debugger or add some log statements to inspect $params.)

You might want to spend some time looking at those two functions (postProcess and sendTemplate). See if there's a way to provide the contactID. If that works out, expand the search and check for other places that work with "event_offline_receipt" or "event_online_receipt".

megabait

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
  • CiviCRM version: 4.6.6
  • CMS version: WordPress 4.2.4
  • MySQL version: MySQL 5.6
  • PHP version: PHP 5.5
Re: Won't converted custom tokens in email
August 19, 2015, 01:27:11 am
Thank you, I will dig in that way

freephile

  • I’m new here
  • *
  • Posts: 1
  • Karma: 0
  • CiviCRM version: 6.7
  • CMS version: Drupal
  • MySQL version: 5.5.44-0ubuntu0.14.04.1
  • PHP version: 5.5.9
Re: Won't converted custom tokens in email
October 07, 2015, 09:36:41 pm
I'm having the same problem.  I created (multi-value) custom fields and they are not expanded, or passed through when using CiviMail.  I'm trying to get to the bottom of this.  So I'm monitoring for a fix; and will post an update if I find a solution.  The Drupal module that I wrote to expose my custom field data is at http://pastebin.com/LaDq0z82

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Won't converted custom tokens in email

This forum was archived on 2017-11-26.