From ea9c9ed4bf8f6cd085874e0c359024f74abce2e6 Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Wed, 3 Mar 2021 18:14:55 +0530 Subject: [PATCH] update to lifetime membership does not clear the end date --- CRM/Member/BAO/Membership.php | 7 ++++++- tests/phpunit/CRM/Member/Form/MembershipTest.php | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 471a15e394..a3f77a558e 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -246,6 +246,11 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership { * @throws CRM_Core_Exception */ public static function create(&$params, $ids = []) { + $isLifeTime = FALSE; + if (!empty($params['membership_type_id'])) { + $memTypeDetails = CRM_Member_BAO_MembershipType::getMembershipType($params['membership_type_id']); + $isLifeTime = $memTypeDetails['duration_unit'] === 'lifetime' ? TRUE : FALSE; + } // always calculate status if is_override/skipStatusCal is not true. // giving respect to is_override during import. CRM-4012 @@ -260,7 +265,7 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership { // @todo enable this once core is using the api. // CRM_Core_Error::deprecatedWarning('Relying on the BAO to clean up dates is deprecated. Call membership create via the api'); } - if (!empty($params['id']) && empty($params[$dateField])) { + if (!empty($params['id']) && empty($params[$dateField]) && !($isLifeTime && $dateField == 'end_date')) { $fieldsToLoad[] = $dateField; } } diff --git a/tests/phpunit/CRM/Member/Form/MembershipTest.php b/tests/phpunit/CRM/Member/Form/MembershipTest.php index 3a00ecbe26..f07bfb90e2 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipTest.php @@ -672,6 +672,13 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { $this->assertEquals(50, $payment['paid']); // balance remaining $this->assertEquals(-25, $payment['balance']); + + //Update to lifetime membership. + $params['membership_type_id'] = [$this->ids['contact']['organization'], $this->ids['membership_type']['lifetime']]; + $form->testSubmit($params); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); + $this->assertEquals($this->ids['membership_type']['lifetime'], $membership['membership_type_id']); + $this->assertTrue(empty($membership['end_date']), 'Lifetime Membership on the individual has an End date.'); } /** -- 2.25.1