From b974584b962ddd1bcb1cfbbd7f6af0c10e9e907d Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Mon, 18 Mar 2019 17:44:21 +1300 Subject: [PATCH] Code cleanup on membership block loop --- CRM/Contribute/Form/ContributionBase.php | 31 ++++++++++++++---------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index f6e71a167d..f8b6f1a146 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -1195,6 +1195,18 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $membershipTypeValues = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, $membershipTypeIds); $this->_membershipTypeValues = $membershipTypeValues; $endDate = NULL; + + // Check if we support auto-renew on this contribution page + // FIXME: If any of the payment processors do NOT support recurring you cannot setup an + // auto-renew payment even if that processor is not selected. + $allowAutoRenewOpt = TRUE; + if (is_array($this->_paymentProcessors)) { + foreach ($this->_paymentProcessors as $id => $val) { + if ($id && !$val['is_recur']) { + $allowAutoRenewOpt = FALSE; + } + } + } foreach ($membershipTypeIds as $value) { $memType = $membershipTypeValues[$value]; if ($selectedMembershipTypeID != NULL) { @@ -1217,23 +1229,16 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { } } elseif ($memType['is_active']) { - $javascriptMethod = NULL; - $allowAutoRenewOpt = (int) $memType['auto_renew']; - if (is_array($this->_paymentProcessors)) { - foreach ($this->_paymentProcessors as $id => $val) { - if ($id && !$val['is_recur']) { - $allowAutoRenewOpt = 0; - continue; - } - } - } - - $javascriptMethod = array('onclick' => "return showHideAutoRenew( this.value );"); - $autoRenewMembershipTypeOptions["autoRenewMembershipType_{$value}"] = (int) $allowAutoRenewOpt * CRM_Utils_Array::value($value, CRM_Utils_Array::value('auto_renew', $this->_membershipBlock));; if ($allowAutoRenewOpt) { + $javascriptMethod = array('onclick' => "return showHideAutoRenew( this.value );"); + $autoRenewMembershipTypeOptions["autoRenewMembershipType_{$value}"] = (int) $memType['auto_renew'] * CRM_Utils_Array::value($value, CRM_Utils_Array::value('auto_renew', $this->_membershipBlock)); $allowAutoRenewMembership = TRUE; } + else { + $javascriptMethod = NULL; + $autoRenewMembershipTypeOptions["autoRenewMembershipType_{$value}"] = 0; + } //add membership type. $radio[$memType['id']] = $this->createElement('radio', NULL, NULL, NULL, -- 2.25.1