Added 'membership_type_id is present check' when saving membership payment.
authorMattias Michaux <mattias.michaux@gmail.com>
Fri, 4 Dec 2015 09:55:24 +0000 (10:55 +0100)
committerMattias Michaux <mattias.michaux@gmail.com>
Fri, 4 Dec 2015 09:55:24 +0000 (10:55 +0100)
CRM/Member/BAO/Membership.php
CRM/Member/BAO/MembershipPayment.php

index e1e7b3ada1b83fae921539dbdd92fb1ad61db9f7..807b26cd7ed0dbbfe2bdb91b31f249f7b77f5d26 100644 (file)
@@ -342,6 +342,7 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership {
     if (!empty($params['relate_contribution_id'])) {
       CRM_Member_BAO_MembershipPayment::create(array(
         'membership_id' => $membership->id,
+        'membership_type_id' => $membership->membership_type_id,
         'contribution_id' => $params['relate_contribution_id'],
       ));
     }
@@ -1783,6 +1784,7 @@ INNER JOIN  civicrm_contact contact ON ( contact.id = membership.contact_id AND
   public static function linkMembershipPayment($membership, $membershipContribution) {
     CRM_Member_BAO_MembershipPayment::create(array(
       'membership_id' => $membership->id,
+      'membership_type_id' => $membership->membership_type_id,
       'contribution_id' => $membershipContribution->id,
     ));
   }
index ff15412bd095f88e27bb5995fde7bbfc50fbd883..f596ecd79a8375bc246b0f5355e89b4fb11c7697 100644 (file)
@@ -67,10 +67,15 @@ class CRM_Member_BAO_MembershipPayment extends CRM_Member_DAO_MembershipPayment
     // table. However, at this stage we have both - there is still quite a bit of refactoring to do to set the line_iten entity_id right the first time
     // however, we can assume at this stage that any contribution id will have only one line item with that membership type in the line item table
     // OR the caller will have taken responsibility for updating the line items themselves so we will update using SQL here
-    $membershipTypeID = civicrm_api3('membership', 'getvalue', array(
+    if (!isset($params['membership_type_id'])) {
+      $membership_type_id = civicrm_api3('membership', 'getvalue', array(
         'id' => $dao->membership_id,
         'return' => 'membership_type_id',
       ));
+    }
+    else {
+      $membership_type_id = $params['membership_type_id'];
+    }
     $sql = "UPDATE civicrm_line_item li
       LEFT JOIN civicrm_price_field_value pv ON pv.id = li.price_field_value_id
       SET entity_table = 'civicrm_membership', entity_id = %1
@@ -78,7 +83,7 @@ class CRM_Member_BAO_MembershipPayment extends CRM_Member_DAO_MembershipPayment
       AND contribution_id = %3";
     CRM_Core_DAO::executeQuery($sql, array(
         1 => array($dao->membership_id, 'Integer'),
-        2 => array($membershipTypeID, 'Integer'),
+        2 => array($membership_type_id, 'Integer'),
         3 => array($dao->contribution_id, 'Integer'),
       ));
     return $dao;