From 9ca53bf16619cf8ef9a37c1bf95ffcd6c25699d3 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 30 Nov 2023 15:12:03 +1300 Subject: [PATCH] Fix to still record empty amount levels for secondary contributions --- CRM/Contribute/Form/Contribution/Confirm.php | 2 +- CRM/Contribute/Form/ContributionBase.php | 27 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 45dd561553..63f76f37a6 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -157,7 +157,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr 'financial_type_id' => $financialTypeID, 'receive_date' => !empty($params['receive_date']) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'), 'tax_amount' => $params['tax_amount'] ?? NULL, - 'amount_level' => $params['amount_level'] ?? NULL, + 'amount_level' => $this->getMainContributionAmountLevel(), 'invoice_id' => $params['invoiceID'], 'currency' => $params['currencyID'], 'is_pay_later' => $params['is_pay_later'] ?? 0, diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 4505f2f027..1ee61f4bcf 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -1209,6 +1209,33 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { return $amount; } + /** + * Get the amount level description for the main contribution. + * + * If there is a separate membership contribution this is the 'other one'. Otherwise there + * is only one. + * + * @return string + * + * @throws \CRM_Core_Exception + */ + protected function getMainContributionAmountLevel(): string { + $amountLevel = []; + if ($this->getSecondaryMembershipContributionLineItems()) { + // This is really only needed transitionally because the + // test ConfirmTest::testSeparatePaymentConfirm has some set up configuration + // issues that will take a bit longer to work through (the labels + // should be Contribution Amount or Other Amount but in that test set up they are not. + return ''; + } + foreach ($this->getMainContributionLineItems() as $lineItem) { + if ($lineItem['label'] !== ts('Contribution Amount') && $lineItem['label'] !== ts('Other Amount')) { + $amountLevel[] = $lineItem['label'] . ' - ' . (float) $lineItem['qty']; + } + } + return empty($amountLevel) ? '' : CRM_Utils_Array::implodePadded($amountLevel); + } + /** * Wrapper for processAmount that also sets autorenew. * -- 2.25.1