From 1f4d7bcba242fb8262b6a5350a62dfc902055d4a Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 20 May 2014 14:23:57 +1200 Subject: [PATCH] further consolidation on membership creation 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 | 7 ++----- CRM/Member/BAO/Membership.php | 14 ++++++-------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 73a808b273..907b546a54 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -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']) { diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 36dabca615..e08b8d6e20 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -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) -- 2.25.1