Skip to content

Commit

Permalink
Extract override default currency function
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Jun 12, 2019
1 parent 5e6d2d1 commit d13eac5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 25 deletions.
8 changes: 1 addition & 7 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions CRM/Contribute/BAO/Contribution/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
9 changes: 1 addition & 8 deletions CRM/Contribute/Form/ContributionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions CRM/Event/Form/Registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 1 addition & 6 deletions CRM/Event/Page/EventInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit d13eac5

Please sign in to comment.