From 919e8652a82baec198f4f094c141c643e0a1710c Mon Sep 17 00:00:00 2001 From: monishdeb Date: Mon, 6 Apr 2015 20:01:40 +0530 Subject: [PATCH] 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 --- CRM/Contribute/BAO/Contribution/Utils.php | 6 +++--- CRM/Contribute/Form/ContributionPage/Amount.php | 6 ++++++ CRM/Member/BAO/Membership.php | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) 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) { -- 2.25.1