Skip to content

Commit

Permalink
Merge pull request #22736 from eileenmcnaughton/membership_message
Browse files Browse the repository at this point in the history
Cleanup on Offline Membership Receipts (ensures variables present across flows)
  • Loading branch information
mlutfy authored Feb 22, 2022
2 parents bd8f40c + 7b2d675 commit 72d90df
Show file tree
Hide file tree
Showing 16 changed files with 4,497 additions and 4,230 deletions.
13 changes: 6 additions & 7 deletions CRM/Batch/Form/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -937,9 +937,6 @@ protected function emailReceipt($form, &$formValues): bool {
$form->assign('module', 'Membership');
$form->assign('contactID', $formValues['contact_id']);

$form->assign('membershipID', CRM_Utils_Array::value('membership_id', $form->_params, CRM_Utils_Array::value('membership_id', $form->_defaultValues)));
$this->assign('contributionID', $this->getCurrentRowContributionID());

if (!empty($formValues['contribution_status_id'])) {
$form->assign('contributionStatusID', $formValues['contribution_status_id']);
$form->assign('contributionStatus', CRM_Contribute_PseudoConstant::contributionStatus($formValues['contribution_status_id'], 'name'));
Expand All @@ -961,16 +958,18 @@ protected function emailReceipt($form, &$formValues): bool {

CRM_Core_BAO_MessageTemplate::sendTemplate(
[
'groupName' => 'msg_tpl_workflow_membership',
'valueName' => 'membership_offline_receipt',
'contactId' => $form->_receiptContactId,
'workflow' => 'membership_offline_receipt',
'from' => $this->getFromEmailAddress(),
'toName' => $form->_contributorDisplayName,
'toEmail' => $form->_contributorEmail,
'PDFFilename' => ts('receipt') . '.pdf',
'isEmailPdf' => Civi::settings()->get('invoice_is_email_pdf'),
'contributionId' => $this->getCurrentRowContributionID(),
'isTest' => (bool) ($form->_action & CRM_Core_Action::PREVIEW),
'modelProps' => [
'contributionId' => $this->getCurrentRowContributionID(),
'contactId' => $form->_receiptContactId,
'membershipId' => $this->getCurrentRowMembershipID(),
],
]
);

Expand Down
29 changes: 29 additions & 0 deletions CRM/Contribute/Form/AbstractEditPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,35 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Contact_Form_Task {

public $_compId;

/**
* Contribution ID.
*
* @var int|null
*/
protected $contributionID;

/**
* Get the contribution id that has been created or is being edited.
*
* @internal - not supported for outside core.
*
* @return int|null
*/
protected function getContributionID(): ?int {
return $this->contributionID;
}

/**
* Set the contribution id that has been created or is being edited.
*
* @internal - not supported for outside core.
*
* @param int|null $contributionID
*/
protected function setContributionID(?int $contributionID): void {
$this->contributionID = $contributionID;
}

/**
* Store the line items if price set used.
* @var array
Expand Down
21 changes: 10 additions & 11 deletions CRM/Member/Form/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -940,12 +940,8 @@ protected function emailReceipt($form, &$formValues) {
}

$form->assign('module', 'Membership');
$form->assign('contactID', $formValues['contact_id']);

$form->assign('membershipID', $this->getMembershipID());

if (!empty($formValues['contribution_id'])) {
$form->assign('contributionID', $formValues['contribution_id']);
$form->assign('currency', CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $formValues['contribution_id'], 'currency'));
}
else {
Expand Down Expand Up @@ -987,16 +983,19 @@ protected function emailReceipt($form, &$formValues) {

CRM_Core_BAO_MessageTemplate::sendTemplate(
[
'groupName' => 'msg_tpl_workflow_membership',
'valueName' => 'membership_offline_receipt',
'contactId' => $form->_receiptContactId,
'workflow' => 'membership_offline_receipt',
'from' => $receiptFrom,
'toName' => $form->_contributorDisplayName,
'toEmail' => $form->_contributorEmail,
'PDFFilename' => ts('receipt') . '.pdf',
'isEmailPdf' => Civi::settings()->get('invoice_is_email_pdf'),
'contributionId' => $formValues['contribution_id'],
'isTest' => (bool) ($form->_action & CRM_Core_Action::PREVIEW),
'modelProps' => [
'receiptText' => $this->getSubmittedValue('receipt_text'),
'contributionId' => $formValues['contribution_id'],
'contactId' => $form->_receiptContactId,
'membershipId' => $this->getMembershipID(),
],
]
);

Expand Down Expand Up @@ -1364,9 +1363,9 @@ public function submit(): void {
if ($this->getSubmittedValue('send_receipt') && $receiptSend) {
$formValues['contact_id'] = $this->_contactID;
$formValues['contribution_id'] = $contributionId;
// We really don't need a distinct receipt_text_signup vs receipt_text_renewal as they are
// handled in the receipt. But by setting one we avoid breaking templates for now
// although at some point we should switch in the templates.
// receipt_text_signup is no longer used in receipts from 5.47
// but may linger in some sites that have not updated their
// templates.
$formValues['receipt_text_signup'] = $formValues['receipt_text'];
// send email receipt
$this->assignBillingName();
Expand Down
20 changes: 11 additions & 9 deletions CRM/Member/Form/MembershipRenewal.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public function buildQuickForm() {

$this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);

$this->add('textarea', 'receipt_text_renewal', ts('Renewal Message'));
$this->add('textarea', 'receipt_text', ts('Renewal Message'));

// Retrieve the name and email of the contact - this will be the TO for receipt email
list($this->_contributorDisplayName,
Expand Down Expand Up @@ -627,7 +627,7 @@ protected function submit() {
'membership_id' => $membership->id,
'contribution_recur_id' => $contributionRecurID,
]);
CRM_Member_BAO_Membership::recordMembershipContribution($temporaryParams);
$this->setContributionID(CRM_Member_BAO_Membership::recordMembershipContribution($temporaryParams)->id);
}

if (!empty($this->_params['send_receipt'])) {
Expand Down Expand Up @@ -671,9 +671,6 @@ protected function sendReceipt($membership) {
CRM_Core_BAO_UFGroup::getValues($this->_contactID, $customFields, $customValues, FALSE, $members);

$this->assign_by_ref('formValues', $this->_params);
if (!empty($this->_params['contribution_id'])) {
$this->assign('contributionID', $this->_params['contribution_id']);
}

$this->assign('membership_name', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
$membership->membership_type_id
Expand All @@ -694,21 +691,26 @@ protected function sendReceipt($membership) {
$this->assign('isAmountzero', 0);
$this->assign('is_pay_later', 0);
$this->assign('isPrimary', 1);
$this->assign('receipt_text_renewal', $this->_params['receipt_text']);
if ($this->_mode === 'test') {
$this->assign('action', '1024');
}
}

list($this->isMailSent) = CRM_Core_BAO_MessageTemplate::sendTemplate(
[
'groupName' => 'msg_tpl_workflow_membership',
'valueName' => 'membership_offline_receipt',
'contactId' => $this->_receiptContactId,
'workflow' => 'membership_offline_receipt',
'from' => $receiptFrom,
'toName' => $this->_contributorDisplayName,
'toEmail' => $this->_contributorEmail,
'isTest' => $this->_mode === 'test',
'PDFFilename' => ts('receipt') . '.pdf',
'isEmailPdf' => Civi::settings()->get('invoice_is_email_pdf'),
'modelProps' => [
'receiptText' => $this->getSubmittedValue('receipt_text'),
'contactId' => $this->_receiptContactId,
'contributionID' => $this->getContributionID(),
'membershipID' => $this->_membershipId,
],
]
);
}
Expand Down
36 changes: 36 additions & 0 deletions CRM/Member/WorkflowMessage/MembershipOfflineReceipt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

use Civi\WorkflowMessage\GenericWorkflowMessage;

/**
* Receipt sent when confirming a back office membership.
*
* @support template-only
*
* @see CRM_Member_Form_MembershipRenewal::sendReceipt
* @see CRM_Member_Form_Membership::emailReceipt
* @see CRM_Batch_Form_Entry::emailReceipt
*/
class CRM_Member_WorkflowMessage_MembershipOfflineReceipt extends GenericWorkflowMessage {
use CRM_Member_WorkflowMessage_MembershipTrait;
public const WORKFLOW = 'membership_offline_receipt';

/**
* Additional text to include in the receipt.
*
* @var string
*
* @scope tplParams as receipt_text
*/
protected $receiptText;

}
27 changes: 27 additions & 0 deletions CRM/Member/WorkflowMessage/MembershipOnlineReceipt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

use Civi\WorkflowMessage\GenericWorkflowMessage;

/**
* Receipt sent when confirming a back office membership.
*
* @support template-only
*
* @see CRM_Member_Form_MembershipRenewal::sendReceipt
* @see CRM_Member_Form_Membership::emailReceipt
* @see CRM_Batch_Form_Entry::emailReceipt
*/
class CRM_Member_WorkflowMessage_MembershipOnlineReceipt extends GenericWorkflowMessage {
use CRM_Member_WorkflowMessage_MembershipTrait;
public const WORKFLOW = 'membership_online_receipt';

}
50 changes: 50 additions & 0 deletions CRM/Member/WorkflowMessage/MembershipTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* @method array getMembership()
* @method ?int getMembershipID()
* @method $this setMembershipID(?int $membershipID)
* @method ?int getContributionID()
* @method $this setContributionID(?int $membershipID)
*/
trait CRM_Member_WorkflowMessage_MembershipTrait {
/**
* The membership.
*
* @var array|null
*
* @scope tokenContext as membership
*/
protected $membership;

/**
* @var int
* @scope tokenContext as membershipId, tplParams as membershipID
*/
protected $membershipID;

/**
* Contribution ID.
*
* @var int
*
* @scope tokenContext as contributionId, tplParams as contributionID
*/
protected $contributionID;

/**
* Set membership object.
*
* @param array $membership
*
* @return $this
*/
public function setMembership(array $membership): self {
$this->membership = $membership;
if (!empty($membership['id'])) {
$this->membershipId = $membership['id'];
}
return $this;
}

}
4 changes: 4 additions & 0 deletions CRM/Utils/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,10 @@ public static function getTokenDeprecations(): array {
'$last_name' => 'contact.last_name',
'$displayName' => 'contact.display_name',
],
'membership_offline_receipt' => [
// receipt_text_renewal appears to be long gone.
'receipt_text_renewal' => 'receipt_text',
],
'pledge_acknowledgement' => [
'$domain' => 'no longer available / relevant',
'$contact' => 'no longer available / relevant',
Expand Down
2 changes: 1 addition & 1 deletion Civi/WorkflowMessage/GenericWorkflowMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct(array $imports = []) {
* The contact receiving this message.
*
* @var int|null
* @scope tokenContext
* @scope tokenContext, tplParams as contactID
* @fkEntity Contact
*/
protected $contactId;
Expand Down
Loading

0 comments on commit 72d90df

Please sign in to comment.