Skip to content

Commit

Permalink
CGP-1472: Prevent changing membership fee if validation fails
Browse files Browse the repository at this point in the history
Included in CiviCRM-Core
PR : civicrm#15895
  • Loading branch information
omarabuhussein authored and erawat committed May 20, 2020
1 parent 457be68 commit 903dba8
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions CRM/Member/Form/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,27 @@ public function buildQuickForm() {
}
}
$totalAmount = CRM_Utils_Array::value('minimum_fee', $values);
//CRM-18827 - override the default value if total_amount is submitted
if (!empty($this->_submitValues['total_amount'])) {

// CRM-18827 - override the default value if total_amount is submitted
// dev/core#778 - This should only happen for the selected membership type!
$isSelectedMembershipType = $values['id'] === $this->_submitValues['membership_type_id'][1];
if ($isSelectedMembershipType && !empty($this->_submitValues['total_amount'])) {
$totalAmount = $this->_submitValues['total_amount'];

$taxRates = CRM_Core_PseudoConstant::getTaxRates();
$financial_type_id = CRM_Utils_Array::value('financial_type_id', $values);
$membershipTypeTaxRate = CRM_Utils_Array::value($financial_type_id, $taxRates);

/**
* dev/core#778: If value was submitted, tax rates will have been added,
* so we need to subtract them, otw they will get recalculated and added
* again by front-end!
*/
if (!empty($membershipTypeTaxRate)) {
$totalAmount = $totalAmount / (1 + $membershipTypeTaxRate / 100);
}
}

// build membership info array, which is used when membership type is selected to:
// - set the payment information block
// - set the max related block
Expand Down

0 comments on commit 903dba8

Please sign in to comment.