Fix tax total not showing on thank you
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 16 Nov 2023 20:53:38 +0000 (09:53 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 17 Nov 2023 00:22:17 +0000 (13:22 +1300)
CRM/Contribute/Form/Contribution/ThankYou.php
CRM/Contribute/Form/ContributionBase.php

index 60e14469b52b1f1b427d75d81d95593c81220307..9c0a93bccf5c7d61cc24216f2c36b6172b2ce21c 100644 (file)
@@ -78,6 +78,8 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont
 
   /**
    * Build the form object.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function buildQuickForm() {
     // FIXME: Some of this code is identical to Confirm.php and should be broken out into a shared function
@@ -109,10 +111,10 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont
           }
         }
       }
-      $this->assign('getTaxDetails', $getTaxDetails);
-      $this->assign('taxTerm', CRM_Invoicing_Utils::getTaxTerm());
-      $this->assign('totalTaxAmount', $params['tax_amount']);
     }
+    $this->assign('getTaxDetails', (bool) $this->order->getTotalTaxAmount());
+    $this->assign('totalTaxAmount', $this->order->getTotalTaxAmount());
+    $this->assign('taxTerm', \Civi::settings()->get('tax_term'));
 
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
       $this->assign('lineItem', $tplLineItems);
index 46fb52bf9d64c165eaaf130a97af9e01cf2aa833..31b76b29f8c42e44bccdc58c6d525047ee0c3266 100644 (file)
@@ -385,6 +385,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
       $this->order = new CRM_Financial_BAO_Order();
       $this->order->setPriceSetID($this->getPriceSetID());
       $this->order->setIsExcludeExpiredFields(TRUE);
+      $this->order->setPriceSelectionFromUnfilteredInput($this->getSubmittedValues());
     }
     else {
       CRM_Core_Error::deprecatedFunctionWarning('forms require a price set ID');
@@ -1242,6 +1243,48 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
     return $this->_ccid ?: CRM_Utils_Request::retrieve('ccid', 'Positive', $this);
   }
 
+  /**
+   * Get the submitted value, accessing it from whatever form in the flow it is
+   * submitted on.
+   *
+   * @param string $fieldName
+   *
+   * @return mixed|null
+   */
+  public function getSubmittedValue(string $fieldName) {
+    $value = $this->controller->exportValue('Main', $fieldName);
+    if (in_array($fieldName, $this->submittableMoneyFields, TRUE)) {
+      return CRM_Utils_Rule::cleanMoney($value);
+    }
+
+    // Numeric fields are not in submittableMoneyFields (for now)
+    $fieldRules = $this->_rules[$fieldName] ?? [];
+    foreach ($fieldRules as $rule) {
+      if ('money' === $rule['type']) {
+        return CRM_Utils_Rule::cleanMoney($value);
+      }
+    }
+    return $value;
+  }
+
+  /**
+   * Get the fields that can be submitted in this form flow.
+   *
+   * This is overridden to make the fields submitted on the first
+   * form (Contribution_Main) available from the others in the same flow
+   * (Contribution_Confirm, Contribution_ThankYou).
+   *
+   * @api This function will not change in a minor release and is supported for
+   * use outside of core. This annotation / external support for properties
+   * is only given where there is specific test cover.
+   *
+   * @return string[]
+   */
+  protected function getSubmittableFields(): array {
+    $fieldNames = array_keys($this->controller->exportValues('Main'));
+    return array_fill_keys($fieldNames, $this->_name);
+  }
+
   /**
    * @return array
    */