CRM-16165 fix - Combining online membership signup with a recurring additional contri...
authormonishdeb <monish.deb@webaccessglobal.com>
Mon, 6 Apr 2015 14:31:40 +0000 (20:01 +0530)
committermonishdeb <monish.deb@webaccessglobal.com>
Mon, 4 May 2015 14:22:52 +0000 (19:52 +0530)
https://issues.civicrm.org/jira/browse/CRM-16165

CRM/Contribute/BAO/Contribution/Utils.php
CRM/Contribute/Form/ContributionPage/Amount.php
CRM/Member/BAO/Membership.php

index b487eda352b826133b0a9116a0507296a7472046..6176f44f54421779d16f403d640aef5613af7355 100644 (file)
@@ -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;
         }
index c6e9348fe2073af4e427c2726c1252b0882702cd..6354c8695bab734ad115bb072dc01d742caeb269 100644 (file)
@@ -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)
index 05c34337768a08383dc84c8e8c3cccfddbc550bf..ae92c41e6c60261e6700340ff582795873e790d0 100644 (file)
@@ -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) {