From ec7af55f06f24cec042f5500b5a4da9312bc55c1 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 30 Jul 2019 18:35:17 +1200 Subject: [PATCH] Reduce reliance on multiple specific but confusing class variables https://github.com/civicrm/civicrm-core/pull/14888 seeks to add auto_renew as a parameter on buildMembershipTypeValues but on digging the results of that are not used much & could be used less. It's only because we store them far away from where we use them that the relative silliness is kinda hidden. This PR removes one of the reliances. Note that testSubmitRecurCompleteInstant is a good one for stepping through this --- CRM/Member/Form/Membership.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 3169844fdc..83a3743bad 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1132,20 +1132,21 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { //take the required membership recur values. if ($this->_mode && !empty($formValues['auto_renew'])) { $params['is_recur'] = $formValues['is_recur'] = TRUE; - $mapping = [ - 'frequency_interval' => 'duration_interval', - 'frequency_unit' => 'duration_unit', - ]; $count = 0; foreach ($this->_memTypeSelected as $memType) { $recurMembershipTypeValues = CRM_Utils_Array::value($memType, - $this->_recurMembershipTypes, [] + $this->allMembershipTypeDetails, [] ); - foreach ($mapping as $mapVal => $mapParam) { - $membershipTypeValues[$memType][$mapVal] = CRM_Utils_Array::value($mapParam, - $recurMembershipTypeValues - ); + if (!$recurMembershipTypeValues['auto_renew']) { + continue; + } + foreach ([ + 'frequency_interval' => 'duration_interval', + 'frequency_unit' => 'duration_unit', + ] as $mapVal => $mapParam) { + $membershipTypeValues[$memType][$mapVal] = $recurMembershipTypeValues[$mapParam]; + if (!$count) { $formValues[$mapVal] = CRM_Utils_Array::value($mapParam, $recurMembershipTypeValues -- 2.25.1