diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index 7af0b6c01049..67c95393882e 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -1736,6 +1736,10 @@ public static function relatedMemberships($contactId, &$params, $ids, $action = //contact before creating new membership record. CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId, $relatedContactId); } + //skip status calculation for pay later memberships. + if (!empty($membershipValues['status_id']) && $membershipValues['status_id'] == $pendingStatusId) { + $membershipValues['skipStatusCal'] = TRUE; + } // check whether we have some related memberships still available $query = " diff --git a/tests/phpunit/api/v3/MembershipTest.php b/tests/phpunit/api/v3/MembershipTest.php index 2f5c6ed8f40b..f58ce8bd2de6 100644 --- a/tests/phpunit/api/v3/MembershipTest.php +++ b/tests/phpunit/api/v3/MembershipTest.php @@ -631,6 +631,28 @@ public function testCreateWithRelationship() { $result = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals(0, $result['count']); + //Create pay_later membership for organization. + $employerId[2] = $this->organizationCreate(array(), 1); + $params = array( + 'contact_id' => $employerId[2], + 'membership_type_id' => $membershipTypeId, + 'source' => 'Test pay later suite', + 'is_pay_later' => 1, + 'status_id' => 5, + ); + $organizationMembership = CRM_Member_BAO_Membership::add($params); + $organizationMembershipID = $organizationMembership->id; + $memberContactId[3] = $this->individualCreate(array('employer_id' => $employerId[2]), 0); + // Check that the employee inherited the membership + $params = array( + 'contact_id' => $memberContactId[3], + 'membership_type_id' => $membershipTypeId, + ); + $result = $this->callAPISuccess('membership', 'get', $params); + $this->assertEquals(1, $result['count']); + $result = $result['values'][$result['id']]; + $this->assertEquals($organizationMembershipID, $result['owner_membership_id']); + // Set up params for enable/disable checks $relationship1 = $this->callAPISuccess('relationship', 'get', array('contact_id_a' => $memberContactId[1])); $params = array(