fixes event#64: Send event confirmation to submitted email address
authorJon Goldberg <jon@megaphonetech.com>
Wed, 29 Sep 2021 17:13:49 +0000 (13:13 -0400)
committerJon Goldberg <jon@megaphonetech.com>
Tue, 5 Oct 2021 18:02:43 +0000 (14:02 -0400)
CRM/Event/BAO/Event.php
CRM/Event/Form/Registration/ThankYou.php
tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php

index 6baa7a793d492fbcb2e4e6cda97cc49394eb6494..a4ba95c2e5895593c474ea6900b176204ba7bda9 100644 (file)
@@ -1108,9 +1108,9 @@ WHERE civicrm_event.is_active = 1
 
     if ($values['event']['is_email_confirm'] || $returnMessageText) {
       list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
-
+      $notifyEmail = CRM_Utils_Array::valueByRegexKey('/^email-/', $participantParams) ?? $email;
       //send email only when email is present
-      if (isset($email) || $returnMessageText) {
+      if (isset($notifyEmail) || $returnMessageText) {
         $preProfileID = $values['custom_pre_id'] ?? NULL;
         $postProfileID = $values['custom_post_id'] ?? NULL;
 
@@ -1153,7 +1153,7 @@ WHERE civicrm_event.is_active = 1
           $customPostTitles = NULL;
         }
         $tplParams = array_merge($values, $participantParams, [
-          'email' => $email,
+          'email' => $notifyEmail,
           'confirm_email_text' => $values['event']['confirm_email_text'] ?? NULL,
           'isShowLocation' => $values['event']['is_show_location'] ?? NULL,
           // The concept of contributeMode is deprecated.
@@ -1233,7 +1233,7 @@ WHERE civicrm_event.is_active = 1
         else {
           $sendTemplateParams['from'] = CRM_Utils_Array::value('confirm_from_name', $values['event']) . " <" . CRM_Utils_Array::value('confirm_from_email', $values['event']) . ">";
           $sendTemplateParams['toName'] = $displayName;
-          $sendTemplateParams['toEmail'] = $email;
+          $sendTemplateParams['toEmail'] = $notifyEmail;
           $sendTemplateParams['autoSubmitted'] = TRUE;
           $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_confirm',
             $values['event']
index a4c2ad048e3ec8649776ddaa6b466ddaf5421613..f7f7e9386df1d442e320953f607f88f98f5d309b 100644 (file)
@@ -73,7 +73,10 @@ class CRM_Event_Form_Registration_ThankYou extends CRM_Event_Form_Registration {
     // Assign the email address from a contact id lookup as in CRM_Event_BAO_Event->sendMail()
     $primaryContactId = $this->get('primaryContactId');
     if ($primaryContactId) {
-      list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($primaryContactId);
+      $email = CRM_Utils_Array::valueByRegexKey('/^email-/', current($this->_params));
+      if (!$email) {
+        $email = CRM_Contact_BAO_Contact::getPrimaryEmail($primaryContactId);
+      }
       $this->assign('email', $email);
     }
     $this->assignToTemplate();
index aeb12efa16aacd50e8b43299e525c86bf66ef42b..2f57e086fdb9e6d1862e75d183ff2439080a7c81 100644 (file)
@@ -595,4 +595,72 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
     $this->submitWithNote($event, $contact_id);
   }
 
+  /**
+   * event#64 - ensure we send to the submitted email, not the primary email when they differ.
+   *
+   * @throws \Exception
+   */
+  public function testSubmitNonPrimaryEmail(): void {
+    $event = $this->eventCreate();
+    $mut = new CiviMailUtils($this, TRUE);
+    $cid = $this->createLoggedInUser();
+    CRM_Event_Form_Registration_Confirm::testSubmit([
+      'id' => $event['id'],
+      'contributeMode' => 'direct',
+      'registerByID' => $cid,
+      'params' => [
+        [
+          'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
+          'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&amp;id=3',
+          'first_name' => 'k',
+          'last_name' => 'p',
+          'email-Other' => 'nonprimaryemail@example.com',
+          'hidden_processor' => '1',
+          'credit_card_number' => '4111111111111111',
+          'cvv2' => '123',
+          'credit_card_exp_date' => [
+            'M' => '1',
+            'Y' => '2019',
+          ],
+          'credit_card_type' => 'Visa',
+          'billing_first_name' => 'p',
+          'billing_middle_name' => '',
+          'billing_last_name' => 'p',
+          'billing_street_address-5' => 'p',
+          'billing_city-5' => 'p',
+          'billing_state_province_id-5' => '1061',
+          'billing_postal_code-5' => '7',
+          'billing_country_id-5' => '1228',
+          'priceSetId' => '6',
+          'price_7' => [
+            13 => 1,
+          ],
+          'payment_processor_id' => '1',
+          'bypass_payment' => '',
+          'MAX_FILE_SIZE' => '33554432',
+          'is_primary' => 1,
+          'is_pay_later' => 0,
+          'campaign_id' => NULL,
+          'defaultRole' => 1,
+          'participant_role_id' => '1',
+          'currencyID' => 'USD',
+          'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1',
+          'amount' => '800.00',
+          'tax_amount' => NULL,
+          'year' => '2019',
+          'month' => '1',
+          'ip_address' => '127.0.0.1',
+          'invoiceID' => '57adc34957a29171948e8643ce906332',
+          'button' => '_qf_Register_upload',
+          'billing_state_province-5' => 'AP',
+          'billing_country-5' => 'US',
+        ],
+      ],
+    ]);
+
+    $mut->checkMailLog(['nonprimaryemail@example.com']);
+    $mut->stop();
+    $mut->clearMessages();
+  }
+
 }