From 24c85a1f02c5381a7edeaf14b35e772889fe0366 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 24 Nov 2023 12:40:16 +1300 Subject: [PATCH] Clean up getMainContributionAmount() function --- CRM/Contribute/Form/Contribution/Confirm.php | 26 -------------------- CRM/Contribute/Form/Contribution/Main.php | 2 +- CRM/Contribute/Form/ContributionBase.php | 17 +++++-------- 3 files changed, 7 insertions(+), 38 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index eff96666f8..1b385d9649 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -2395,32 +2395,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr } } - /** - * Get the amount for the main contribution. - * - * The goal is to expand this function so that all the argy-bargy of figuring out the amount - * winds up here as the main spaghetti shrinks. - * - * If there is a separate membership contribution this is the 'other one'. Otherwise there - * is only one. - * - * @todo - move this to the parent, replace existing (some tests to fight). - * - * @param $params - * - * @return float - * - * @throws \CRM_Core_Exception - */ - protected function getMainContributionAmount($params = []) { - $amount = 0; - foreach ($this->getMainContributionLineItems() as $lineItem) { - // Line total inclusive should really be always set but this is a safe fall back. - $amount += $lineItem['line_total_inclusive'] ?? ($lineItem['line_total'] + $lineItem['tax_amount']); - } - return $amount; - } - /** * Complete transaction if payment has been processed. * diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 19c02e2c63..5a88a8833f 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -1263,7 +1263,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu $params['separate_amount'] = $params['amount']; // @todo - stepping through the code indicates that amount is always set before this point so it never matters. // Move more of the above into this function... - $params['amount'] = $this->getMainContributionAmount($params); + $params['amount'] = $this->getMainContributionAmount(); //If the membership & contribution is used in contribution page & not separate payment $memPresent = $membershipLabel = $fieldOption = NULL; $proceFieldAmount = 0; diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index a4658fc71c..2342dd3d79 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -1109,25 +1109,20 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { /** * Get the amount for the main contribution. * - * The goal is to expand this function so that all the argy-bargy of figuring out the amount - * winds up here as the main spaghetti shrinks. - * * If there is a separate membership contribution this is the 'other one'. Otherwise there * is only one. * - * @param $params - * * @return float * * @throws \CRM_Core_Exception */ - protected function getMainContributionAmount($params) { - if (!empty($params['selectMembership'])) { - if (empty($params['amount']) && !$this->_separateMembershipPayment) { - return CRM_Member_BAO_MembershipType::getMembershipType($params['selectMembership'])['minimum_fee'] ?? 0; - } + protected function getMainContributionAmount(): float { + $amount = 0; + foreach ($this->getMainContributionLineItems() as $lineItem) { + // Line total inclusive should really be always set but this is a safe fall back. + $amount += $lineItem['line_total_inclusive'] ?? ($lineItem['line_total'] + $lineItem['tax_amount']); } - return $params['amount'] ?? 0; + return $amount; } /** -- 2.25.1