Show Membership Info on membership pay later receipt
authorEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 17 Nov 2023 06:13:42 +0000 (19:13 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 19 Nov 2023 22:57:05 +0000 (11:57 +1300)
CRM/Contribute/BAO/Contribution.php
CRM/Contribute/BAO/ContributionPage.php
CRM/Contribute/Form/Contribution/Confirm.php
tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php
xml/templates/message_templates/membership_online_receipt_html.tpl

index 8eb7f8ad56024cc8464d9363c0973af66df5e5c6..331daa89962c009f0f26d658d3285da48110f08d 100644 (file)
@@ -2632,7 +2632,6 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
         foreach ($this->_relatedObjects['membership'] as $membership) {
           if ($membership->id) {
             $values['membership_id'] = $membership->id;
-            $values['isMembership'] = TRUE;
             $values['membership_assign'] = TRUE;
 
             // need to set the membership values here
index a2a5ce289d62a2d4828dcd3533bc77a14ee39000..43c385ed5654a557946b4da45ef1246d66a9cbe3 100644 (file)
@@ -405,11 +405,18 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
       }
 
       // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not
+      $tokenContext = ['contactId' => (int) $contactID];
+      if (!empty($tplParams['contributionID'])) {
+        $tokenContext['contributionId'] = $tplParams['contributionID'];
+      }
+      if (!empty($values['membership_id'])) {
+        $tokenContext['membershipId'] = $values['membership_id'];
+      }
       $sendTemplateParams = [
-        'workflow' => !empty($values['isMembership']) ? 'membership_online_receipt' : 'contribution_online_receipt',
+        'workflow' => !empty($values['membership_id']) ? 'membership_online_receipt' : 'contribution_online_receipt',
         'contactId' => $contactID,
         'tplParams' => $tplParams,
-        'tokenContext' => $tplParams['contributionID'] ? ['contributionId' => (int) $tplParams['contributionID'], 'contactId' => $contactID] : ['contactId' => $contactID],
+        'tokenContext' => $tokenContext,
         'isTest' => $isTest,
         'PDFFilename' => 'receipt.pdf',
       ];
index d46780709312eedba07ca8357eb6b9c76e8e6c8d..c4c1c98ce605f2b3dfc8af832962ed80f7167a2e 100644 (file)
@@ -1437,7 +1437,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
     $membershipContribution = NULL;
     $isTest = $membershipParams['is_test'] ?? FALSE;
     $errors = $paymentResults = [];
-    $this->_values['isMembership'] = TRUE;
+
     $isRecurForFirstTransaction = $this->_params['is_recur'] ?? $membershipParams['is_recur'] ?? NULL;
 
     $totalAmount = $membershipParams['amount'];
@@ -1586,7 +1586,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
 
           //CRM-15232: Check if membership is created and on the basis of it use
           //membership receipt template to send payment receipt
-          $this->_values['isMembership'] = TRUE;
+          $this->_values['membership_id'] = $membership->id;
         }
       }
       if ($this->_priceSetId && !empty($this->_useForMember) && !empty($this->_lineItem)) {
@@ -1670,6 +1670,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
     $emailValues = array_merge($membershipParams, $this->_values);
     $emailValues['membership_assign'] = 1;
     $emailValues['useForMember'] = !empty($this->_useForMember);
+    $emailValues['membership_id'] = !empty($membership) ? $membership->id : NULL;
 
     // Finally send an email receipt for pay-later scenario (although it might sometimes be caught above!)
     if ($totalAmount == 0) {
index facd0f11cc55c1068bf5ff39aaa8f429e6db9c12..cc246b2706c5e22e3fdc67265ee319e7156bc12b 100644 (file)
@@ -224,8 +224,7 @@ class CRM_Contribute_Form_Contribution_ConfirmTest extends CiviUnitTestCase {
       'Membership Information',
       'Membership Type       </td>
        <td style="padding: 4px; border-bottom: 1px solid #999;">
-        General
-       </td>',
+         General       </td>',
       '$1,000.00',
       'Membership Start Date',
       '************1111',
index e469152b026713a3cd9517cb432e0236f5479d59..fc3765628f1c48bdf7d7af4a630b2ed5917c832a 100644 (file)
@@ -33,7 +33,7 @@
   </tr>
   </table>
   <table style="width:100%; max-width:500px; border: 1px solid #999; margin: 1em 0em 1em; border-collapse: collapse;">
-    {if $membership_assign && !$useForMember}
+    {if {membership.id|boolean} && !$isShowLineItems}
       <tr>
        <th {$headerStyle}>
         {ts}Membership Information{/ts}
         {ts}Membership Type{/ts}
        </td>
        <td {$valueStyle}>
-        {$membership_name}
+         {ts}{membership.membership_type_id:name}{/ts}
        </td>
       </tr>
-      {if $mem_start_date}
+      {if {membership.start_date|boolean}}
        <tr>
         <td {$labelStyle}>
          {ts}Membership Start Date{/ts}
         </td>
         <td {$valueStyle}>
-         {$mem_start_date|crmDate}
+          {membership.start_date}
         </td>
        </tr>
       {/if}
-      {if $mem_end_date}
+      {if {membership.end_date|boolean}}
        <tr>
         <td {$labelStyle}>
          {ts}Membership Expiration Date{/ts}
         </td>
         <td {$valueStyle}>
-          {$mem_end_date|crmDate}
+          {membership.end_date}
         </td>
        </tr>
       {/if}