further consolidation on membership creation
authorEileen McNaughton <eileen@fuzion.co.nz>
Tue, 20 May 2014 02:23:57 +0000 (14:23 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Wed, 28 May 2014 07:44:25 +0000 (19:44 +1200)
comment fixes

enotice fix

further refactoring to pass more params into smaller functions to make fixing membership line items doable

CRM/Contribute/Form/Contribution/Confirm.php
CRM/Member/BAO/Membership.php

index 73a808b273401263ff973ffcf6ac7849db5ae212..907b546a54f49a348949d66d41b573a8ddef72c9 100644 (file)
@@ -1743,12 +1743,9 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
   {
     try {
 
-      $singleMembershipTypeID = $membershipTypeID = $membershipParams['selectMembership'];
-      if (is_array($membershipTypeID) && count($membershipTypeID) == 1) {
-        $singleMembershipTypeID = $membershipTypeID[0];
-      }
+      $membershipTypeID = $membershipParams['selectMembership'];
 
-      $membershipDetails = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, $singleMembershipTypeID);
+      $membershipDetails = CRM_Member_BAO_Membership::buildMembershipTypeValues($this);
       $this->assign('membership_name', CRM_Utils_Array::value('name', $membershipDetails));
       $isPaidMembership = FALSE;
       if($this->_amount > 0.0 && $membershipParams['amount']) {
index 36dabca615639bade5bfc3d4b23f17eeccc21941..e08b8d6e20fbd1b5a700b4be3eae70a1806d5c85 100644 (file)
@@ -1309,7 +1309,7 @@ AND civicrm_membership.is_test = %2";
         $typesTerms = CRM_Utils_Array::value('types_terms', $membershipParams, array());
         foreach ($membershipTypeID as $memType) {
           $numTerms = CRM_Utils_Array::value($memType, $typesTerms, 1);
-          $createdMemberships[$memType] = self::createOrRenewMembership($membershipParams, $contactID, $customFieldsFormatted, $membershipID, $memType, $isTest, $numTerms, $membershipContribution, $createdMemberships);
+          $createdMemberships[$memType] = self::createOrRenewMembership($membershipParams, $contactID, $customFieldsFormatted, $membershipID, $memType, $isTest, $numTerms, $membershipContribution, $form);
         }
         if ($form->_priceSetId && !empty($form->_useForMember) && !empty($form->_lineItem)) {
           foreach ($form->_lineItem[$form->_priceSetId] as & $priceFieldOp) {
@@ -1328,10 +1328,6 @@ AND civicrm_membership.is_test = %2";
           $form->assign('lineItem', $form->_lineItem);
         }
       }
-      else {
-        $numTerms = CRM_Utils_Array::value('types_terms', $membershipParams, 1);
-        $createdMemberships[$membershipTypeID] = self::createOrRenewMembership($membershipParams, $contactID, $customFieldsFormatted, $membershipID, $membershipTypeID, $isTest, $numTerms, $membershipContribution, $createdMemberships);
-      }
     }
 
     if (!empty($errors)) {
@@ -1352,8 +1348,11 @@ AND civicrm_membership.is_test = %2";
       );
       $form->_params['createdMembershipIDs'][] = $createdMembership->id;
     }
+    if(count($createdMemberships) == 1) {
+      //presumably this is only relevant for exactly 1 membership
+      $form->_params['membershipID'] = $form->_values['membership_id'] = $createdMembership->id;
+    }
 
-    $form->_params['membershipID'] = $membership->id;
     if ($form->_contributeMode == 'notify') {
       if ($form->_values['is_monetary'] && $form->_amount > 0.0 && !$form->_params['is_pay_later']) {
         // call postProcess hook before leaving
@@ -1364,7 +1363,6 @@ AND civicrm_membership.is_test = %2";
       }
     }
 
-    $form->_values['membership_id'] = $membership->id;
     if (isset($membershipContributionID)) {
       $form->_values['contribution_id'] = $membershipContributionID;
     }
@@ -1467,7 +1465,7 @@ AND civicrm_membership.is_test = %2";
     // check is it pending. - CRM-4555
     list($pending, $contributionRecurID, $changeToday, $membershipSource, $isPayLater, $campaignId) = self::extractFormValues($form, $changeToday, $membershipTypeDetails);
     list($membership, $renewalMode, $dates) = self::renewMembership($contactID, $membershipTypeID, $is_test, $changeToday, $modifiedID, $customFieldsFormatted, $numRenewTerms, $membershipID, $pending, $allStatus, $membershipTypeDetails, $contributionRecurID, $format, $membershipSource, $ids, $statusFormat, $isPayLater, $campaignId);
-    $form->set('renewal_mode', TRUE);
+    $form->set('renewal_mode', $renewalMode);
     if (!empty($dates)) {
       $form->assign('mem_start_date',
         CRM_Utils_Date::customFormat($dates['start_date'], $format)