Skip to content

Commit

Permalink
[REF] Minor code clean up
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eileenmcnaughton committed Jul 27, 2020
1 parent 9170f16 commit 96f8e7f
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 96f8e7f

Please sign in to comment.