diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index d6087b9c399fd16e45a381665b7e59dc848cef99..f14ae8ff5e746a6334a4d623e9515048d630fc17 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -1681,17 +1681,26 @@ LEFT JOIN civicrm_contribution contribution ON ( componentPayment.contribution_ // else fall back to using current membership type $dao->free(); + // Figure out number of terms + $numterms = 1; + $lineitems = CRM_Price_BAO_LineItem::getLineItems($contributionId, 'contribution'); + foreach ($lineitems as $lineitem) { + if ($membership->membership_type_id == CRM_Utils_Array::value('membership_type_id', $lineitem)) { + $numterms = CRM_Utils_Array::value('membership_num_terms', $lineitem); + + // in case membership_num_terms comes through as null or zero + $numterms = $numterms >= 1 ? $numterms : 1; + break; + } + } + if ($currentMembership) { - CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, - $changeToday = NULL - ); - $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, - $changeToday = NULL - ); + CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, NULL); + $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, NULL, NULL, $numterms); $dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format); } else { - $dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id); + $dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id, null, null, null, $numterms); } //get the status for membership. diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index 89723470f15cea356e81ce56f81a3cde239454c8..2c3de75543e7ba552f39001e615ad1dfe3abf739 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -112,6 +112,7 @@ class CRM_Price_BAO_LineItem extends CRM_Price_DAO_LineItem { pf.label as field_title, pf.html_type, pfv.membership_type_id, + pfv.membership_num_terms, li.price_field_id, li.participant_count, li.price_field_value_id, @@ -158,6 +159,7 @@ class CRM_Price_BAO_LineItem extends CRM_Price_DAO_LineItem { 'description' => $dao->description, 'entity_id' => $entityId, 'membership_type_id' => $dao->membership_type_id, + 'membership_num_terms' => $dao->membership_num_terms, ); } return $lineItems;