From 820345a2b7f685b995e86c524eaa94ae19dc446e Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 30 Nov 2023 00:49:45 +1300 Subject: [PATCH] Fix a whole lot of conditional assignments on confirm & thank you pages --- CRM/Contribute/Form/ContributionBase.php | 68 +++++++----------------- 1 file changed, 19 insertions(+), 49 deletions(-) diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 4a37189126..4505f2f027 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -710,55 +710,25 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { */ public function assignToTemplate() { $this->set('name', $this->assignBillingName($this->_params)); - - $this->assign('paymentProcessor', $this->_paymentProcessor); - $vars = [ - 'amount', - 'currencyID', - 'credit_card_type', - 'trxn_id', - 'amount_level', - ]; - - if (isset($this->_values['is_recur']) && !empty($this->_paymentProcessor['is_recur'])) { - $this->assign('is_recur_enabled', 1); - $vars = array_merge($vars, [ - 'is_recur', - 'frequency_interval', - 'frequency_unit', - 'installments', - ]); - } - - if (CRM_Core_Component::isEnabled('CiviPledge') && - !empty($this->_params['is_pledge']) - ) { - // TODO: Assigned variable appears to be unused - $this->assign('pledge_enabled', 1); - - $vars = array_merge($vars, [ - 'is_pledge', - 'pledge_frequency_interval', - 'pledge_frequency_unit', - 'pledge_installments', - ]); - } - - // @todo - stop setting amount level in this function - use $this->order->getAmountLevel() - // to cover all variants. - if (isset($this->_params['amount_other']) || isset($this->_params['selectMembership'])) { - $this->_params['amount_level'] = ''; - } - - foreach ($vars as $v) { - if (isset($this->_params[$v])) { - if ($v === 'amount' && $this->_params[$v] === 0) { - $this->_params[$v] = CRM_Utils_Money::format($this->_params[$v], NULL, NULL, TRUE); - } - $this->assign($v, $this->_params[$v]); - } - } - + $this->assign('currencyID', $this->_params['currencyID'] ?? NULL); + $this->assign('credit_card_type', $this->_params['credit_card_type'] ?? NULL); + $this->assign('trxn_id', $this->_params['trxn_id'] ?? NULL); + $this->assign('amount_level', $this->order->getAmountLevel()); + $this->assign('amount', $this->getMainContributionAmount() > 0 ? CRM_Utils_Money::format($this->getMainContributionAmount(), NULL, NULL, TRUE) : NULL); + + $isRecurEnabled = isset($this->_values['is_recur']) && !empty($this->_paymentProcessor['is_recur']); + $this->assign('is_recur_enabled', $isRecurEnabled); + $this->assign('is_recur', $isRecurEnabled ? ($this->_params['is_recur'] ?? NULL) : NULL); + $this->assign('frequency_interval', $isRecurEnabled ? ($this->_params['frequency_interval'] ?? NULL) : NULL); + $this->assign('frequency_unit', $isRecurEnabled ? ($this->_params['frequency_unit'] ?? NULL) : NULL); + $this->assign('installments', $isRecurEnabled ? ($this->_params['installments'] ?? NULL) : NULL); + $isPledgeEnabled = CRM_Core_Component::isEnabled('CiviPledge') && !empty($this->_params['is_pledge']); + // @todo Assigned pledge_enabled variable appears to be unused + $this->assign('pledge_enabled', $isPledgeEnabled); + $this->assign('is_pledge', $isPledgeEnabled ? ($this->_params['is_pledge'] ?? NULL) : NULL); + $this->assign('pledge_frequency_interval', $isPledgeEnabled ? ($this->_params['pledge_frequency_interval'] ?? NULL) : NULL); + $this->assign('pledge_frequency_unit', $isPledgeEnabled ? ($this->_params['pledge_frequency_unit'] ?? NULL) : NULL); + $this->assign('pledge_installments', $isPledgeEnabled ? ($this->_params['pledge_installments'] ?? NULL) : NULL); $this->assign('address', CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters($this->_params)); $isDisplayOnBehalf = !empty($this->_params['onbehalf_profile_id']) && !empty($this->_params['onbehalf']); -- 2.25.1