From d13eac5a0bacbdb633cf1cf4c5eee0c45a70e594 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Tue, 11 Jun 2019 18:39:26 +0100 Subject: [PATCH] Extract override default currency function --- CRM/Contribute/BAO/Contribution.php | 8 +------- CRM/Contribute/BAO/Contribution/Utils.php | 12 ++++++++++++ CRM/Contribute/Form/ContributionBase.php | 9 +-------- CRM/Event/Form/Registration.php | 5 +---- CRM/Event/Page/EventInfo.php | 7 +------ 5 files changed, 16 insertions(+), 25 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 6a81bc618587..e89776de28dd 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2943,13 +2943,7 @@ public function _gatherMessageValues($input, &$values, $ids = []) { if (!isset($this->_relatedObjects['contributionPage'])) { $this->loadRelatedEntitiesByID(['contributionPage' => $this->contribution_page_id]); } - // CRM-8254 - override default currency if applicable - $config = CRM_Core_Config::singleton(); - $config->defaultCurrency = CRM_Utils_Array::value( - 'currency', - $values, - $config->defaultCurrency - ); + CRM_Contribute_BAO_Contribution_Utils::overrideDefaultCurrency($values); } } // no contribution page -probably back office diff --git a/CRM/Contribute/BAO/Contribution/Utils.php b/CRM/Contribute/BAO/Contribution/Utils.php index 08c84098c384..2b1fb7a9c0f5 100644 --- a/CRM/Contribute/BAO/Contribution/Utils.php +++ b/CRM/Contribute/BAO/Contribution/Utils.php @@ -640,4 +640,16 @@ public static function getContributionStatuses($usedFor = 'contribution', $id = return $statuses; } + /** + * CRM-8254 / CRM-6907 - override default currency if applicable + * these lines exist to support a non-default currency on the form but are probably + * obsolete & meddling wth the defaultCurrency is not the right approach.... + * + * @param array $params + */ + public static function overrideDefaultCurrency($params) { + $config = CRM_Core_Config::singleton(); + $config->defaultCurrency = CRM_Utils_Array::value('currency', $params, $config->defaultCurrency); + } + } diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 18fcdc93be35..ea0e2cc0c16f 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -479,14 +479,7 @@ public function preProcess() { // This can, for example, by used by payment processors using client side encryption $this->assign('currency', $this->getCurrency()); - //CRM-6907 - // these lines exist to support a non-default currenty on the form but are probably - // obsolete & meddling wth the defaultCurrency is not the right approach.... - $config = CRM_Core_Config::singleton(); - $config->defaultCurrency = CRM_Utils_Array::value('currency', - $this->_values, - $config->defaultCurrency - ); + CRM_Contribute_BAO_Contribution_Utils::overrideDefaultCurrency($this->_values); //lets allow user to override campaign. $campID = CRM_Utils_Request::retrieve('campID', 'Positive', $this); diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index af19e4423678..89528b80b9e7 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -419,10 +419,7 @@ public function preProcess() { $this->assign('bltID', $this->_bltID); $isShowLocation = CRM_Utils_Array::value('is_show_location', $this->_values['event']); $this->assign('isShowLocation', $isShowLocation); - //CRM-6907 - $config->defaultCurrency = CRM_Utils_Array::value('currency', $this->_values['event'], - $config->defaultCurrency - ); + CRM_Contribute_BAO_Contribution_Utils::overrideDefaultCurrency($this->_values['event']); //lets allow user to override campaign. $campID = CRM_Utils_Request::retrieve('campID', 'Positive', $this); diff --git a/CRM/Event/Page/EventInfo.php b/CRM/Event/Page/EventInfo.php index 6cdcab5bdddc..b6f02a0688ca 100644 --- a/CRM/Event/Page/EventInfo.php +++ b/CRM/Event/Page/EventInfo.php @@ -96,12 +96,7 @@ public function run() { // show event fees. if ($this->_id && !empty($values['event']['is_monetary'])) { - //CRM-6907 - $config = CRM_Core_Config::singleton(); - $config->defaultCurrency = CRM_Utils_Array::value('currency', - $values['event'], - $config->defaultCurrency - ); + CRM_Contribute_BAO_Contribution_Utils::overrideDefaultCurrency($values['event']); //CRM-10434 $discountId = CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event');