Fix to still record empty amount levels for secondary contributions
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 30 Nov 2023 02:12:03 +0000 (15:12 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 30 Nov 2023 02:12:03 +0000 (15:12 +1300)
CRM/Contribute/Form/Contribution/Confirm.php
CRM/Contribute/Form/ContributionBase.php

index 45dd561553cf03d81517e46214b4cc8ff79dc801..63f76f37a6a8b9d1860a6f76602bdced20087035 100644 (file)
@@ -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,
index 4505f2f027322c91a68fbbb84825b2dcbf2d7edf..1ee61f4bcfd40d51ec639112388bb3c827b543aa 100644 (file)
@@ -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.
    *