From 984c0aff2e12579a2bc538c1a8be2c454d314792 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 17 Nov 2023 09:53:38 +1300 Subject: [PATCH] Fix tax total not showing on thank you --- CRM/Contribute/Form/Contribution/ThankYou.php | 8 ++-- CRM/Contribute/Form/ContributionBase.php | 43 +++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/ThankYou.php b/CRM/Contribute/Form/Contribution/ThankYou.php index 60e14469b5..9c0a93bccf 100644 --- a/CRM/Contribute/Form/Contribution/ThankYou.php +++ b/CRM/Contribute/Form/Contribution/ThankYou.php @@ -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); diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 46fb52bf9d..31b76b29f8 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -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 */ -- 2.25.1