From 96f8e7f680e66ed56885a70311eda506a27bb55a Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 27 Jul 2020 15:55:44 +1200 Subject: [PATCH] [REF] Minor code clean up This just consolidates a little of the code used to determin if an email receipt should be sent. It's clear that there is more code above that could be pulled into this & combined with the isEmailReceipt function but I wanted to just offer up a small reviewable change unless there is reviewer enthusiasm for more --- CRM/Contribute/BAO/Contribution.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 0ef2ddde7606..6c5df3c357a0 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -4489,9 +4489,6 @@ public static function completeOrder($input, &$ids, $objects, $transaction = NUL $contributionParams['financial_type_id'] = $contribution->financial_type_id; $values = []; - if (isset($input['is_email_receipt'])) { - $values['is_email_receipt'] = $input['is_email_receipt']; - } if ($input['component'] == 'contribute') { if ($contribution->contribution_page_id) { @@ -4505,11 +4502,7 @@ public static function completeOrder($input, &$ids, $objects, $transaction = NUL $values['title'] = $source = ts('Offline Recurring Contribution'); } - if (isset($input['is_email_receipt'])) { - // CRM-19601 - we may have overwritten this above. - $values['is_email_receipt'] = $input['is_email_receipt']; - } - elseif ($recurContrib && $recurringContributionID) { + if ($recurContrib && $recurringContributionID) { //CRM-13273 - is_email_receipt setting on recurring contribution should take precedence over contribution page setting // but CRM-16124 if $input['is_email_receipt'] is set then that should not be overridden. // dev/core#1245 this maybe not the desired effect because the default value for is_email_receipt is set to 0 rather than 1 in @@ -4577,11 +4570,13 @@ public static function completeOrder($input, &$ids, $objects, $transaction = NUL CRM_Activity_BAO_Activity::addActivity($contribution, NULL, $targetContactID); } + $isEmailReceipt = !array_key_exists('is_email_receipt', $values) || $values['is_email_receipt'] == 1; + if (isset($input['is_email_receipt'])) { + $isEmailReceipt = $input['is_email_receipt']; + } // CRM-9132 legacy behaviour was that receipts were sent out in all instances. Still sending // when array_key 'is_email_receipt doesn't exist in case some instances where is needs setting haven't been set - if (!array_key_exists('is_email_receipt', $values) || - $values['is_email_receipt'] == 1 - ) { + if ($isEmailReceipt) { civicrm_api3('Contribution', 'sendconfirmation', [ 'id' => $contribution->id, 'payment_processor_id' => $paymentProcessorId,