From: monishdeb Date: Mon, 6 Apr 2015 14:31:40 +0000 (+0530) Subject: CRM-16165 fix - Combining online membership signup with a recurring additional contri... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=919e8652a82baec198f4f094c141c643e0a1710c;p=civicrm-core.git CRM-16165 fix - Combining online membership signup with a recurring additional contribution results in incorrect recurring contribution amount and frequency https://issues.civicrm.org/jira/browse/CRM-16165 --- diff --git a/CRM/Contribute/BAO/Contribution/Utils.php b/CRM/Contribute/BAO/Contribution/Utils.php index b487eda352..6176f44f54 100644 --- a/CRM/Contribute/BAO/Contribution/Utils.php +++ b/CRM/Contribute/BAO/Contribution/Utils.php @@ -225,10 +225,10 @@ class CRM_Contribute_BAO_Contribution_Utils { // (i.e., the amount NOT associated with the membership). Temporarily // cache the is_recur values so we can process the additional gift as a // one-off payment. - if ($form->_membershipBlock['is_separate_payment']) { + if ($form->_membershipBlock['is_separate_payment'] && !empty($form->_params['auto_renew'])) { $cachedFormValue = CRM_Utils_Array::value('is_recur', $form->_values); - unset($form->_values['is_recur']); $cachedParamValue = CRM_Utils_Array::value('is_recur', $paymentParams); + unset($form->_values['is_recur']); unset($paymentParams['is_recur']); } @@ -244,7 +244,7 @@ class CRM_Contribute_BAO_Contribution_Utils { ); // restore cached values (part of fix for CRM-14354) - if ($form->_membershipBlock['is_separate_payment']) { + if (!empty($cachedFormValue)) { $form->_values['is_recur'] = $cachedFormValue; $paymentParams['is_recur'] = $cachedParamValue; } diff --git a/CRM/Contribute/Form/ContributionPage/Amount.php b/CRM/Contribute/Form/ContributionPage/Amount.php index c6e9348fe2..6354c8695b 100644 --- a/CRM/Contribute/Form/ContributionPage/Amount.php +++ b/CRM/Contribute/Form/ContributionPage/Amount.php @@ -313,6 +313,12 @@ SELECT id if ($membershipBlock->is_separate_payment && empty($fields['amount_block_is_active'])) { $errors['amount_block_is_active'] = ts('To disable Contribution Amounts section you need to first disable Separate Membership Payment option from Membership Settings.'); } + + //CRM-16165, Don't allow reccuring contribution if membership block contain any renewable membership option + $membershipTypes = unserialize($membershipBlock->membership_types); + if (!empty($fields['is_recur']) && !empty($membershipTypes) && count(array_filter($membershipTypes)) != 0) { + $errors['is_recur'] = ts('You cannot enable both Recurring Contributions and Auto-renew memberships on the same online contribution page.'); + } } //check for the amount label (mandatory) diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 05c3433776..ae92c41e6c 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1354,6 +1354,9 @@ AND civicrm_membership.is_test = %2"; if ($isProcessSeparateMembershipTransaction) { try { $lineItems = $form->_lineItem = $membershipLineItems; + if (empty($form->_params['auto_renew']) && !empty($membershipParams['is_recur'])) { + unset($membershipParams['is_recur']); + } $membershipContribution = self::processSecondaryFinancialTransaction($contactID, $form, $membershipParams, $isTest, $membershipLineItems, CRM_Utils_Array::value('minimum_fee', $membershipDetails, 0), CRM_Utils_Array::value('financial_type_id', $membershipDetails)); } catch (CRM_Core_Exception $e) {