Fix a whole lot of conditional assignments on confirm & thank you pages
authorEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 29 Nov 2023 11:49:45 +0000 (00:49 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 29 Nov 2023 23:56:16 +0000 (12:56 +1300)
CRM/Contribute/Form/ContributionBase.php

index 4a37189126b57b83b490d983fa11cff066b46973..4505f2f027322c91a68fbbb84825b2dcbf2d7edf 100644 (file)
@@ -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']);