From: Eileen McNaughton Date: Fri, 17 Nov 2023 06:13:42 +0000 (+1300) Subject: Show Membership Info on membership pay later receipt X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a98083964684404102feee3dd93b9b368345fb02;p=civicrm-core.git Show Membership Info on membership pay later receipt --- diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 8eb7f8ad56..331daa8996 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -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 diff --git a/CRM/Contribute/BAO/ContributionPage.php b/CRM/Contribute/BAO/ContributionPage.php index a2a5ce289d..43c385ed56 100644 --- a/CRM/Contribute/BAO/ContributionPage.php +++ b/CRM/Contribute/BAO/ContributionPage.php @@ -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', ]; diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index d467807093..c4c1c98ce6 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -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) { diff --git a/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php b/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php index facd0f11cc..cc246b2706 100644 --- a/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php @@ -224,8 +224,7 @@ class CRM_Contribute_Form_Contribution_ConfirmTest extends CiviUnitTestCase { 'Membership Information', 'Membership Type - General - ', + General ', '$1,000.00', 'Membership Start Date', '************1111', diff --git a/xml/templates/message_templates/membership_online_receipt_html.tpl b/xml/templates/message_templates/membership_online_receipt_html.tpl index e469152b02..fc3765628f 100644 --- a/xml/templates/message_templates/membership_online_receipt_html.tpl +++ b/xml/templates/message_templates/membership_online_receipt_html.tpl @@ -33,7 +33,7 @@ - {if $membership_assign && !$useForMember} + {if {membership.id|boolean} && !$isShowLineItems} - {if $mem_start_date} + {if {membership.start_date|boolean}} {/if} - {if $mem_end_date} + {if {membership.end_date|boolean}} {/if}
{ts}Membership Information{/ts} @@ -44,26 +44,26 @@ {ts}Membership Type{/ts} - {$membership_name} + {ts}{membership.membership_type_id:name}{/ts}
{ts}Membership Start Date{/ts} - {$mem_start_date|crmDate} + {membership.start_date}
{ts}Membership Expiration Date{/ts} - {$mem_end_date|crmDate} + {membership.end_date}