From c372b01c376de0beddd339cbe6a6b5b5cc1e14d3 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 19 Feb 2015 11:46:08 -0500 Subject: [PATCH] Allow autorenew when there's a single radio group in a price set. --- CRM/Price/BAO/PriceSet.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index 621f2aac28..bf297b8c63 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -1065,7 +1065,7 @@ GROUP BY mt.member_of_contact_id"; // Auto renew checkbox should be frozen if for all the membership type auto renew is required // get the membership type auto renew option and check if required or optional - $query = 'SELECT mt.auto_renew, mt.duration_interval, mt.duration_unit + $query = 'SELECT mt.auto_renew, mt.duration_interval, mt.duration_unit, pf.id, pf.html_type FROM civicrm_price_field_value pfv INNER JOIN civicrm_membership_type mt ON pfv.membership_type_id = mt.id INNER JOIN civicrm_price_field pf ON pfv.price_field_id = pf.id @@ -1077,7 +1077,10 @@ GROUP BY mt.member_of_contact_id"; $dao = CRM_Core_DAO::executeQuery($query, $params); $autoRenewOption = 2; - $interval = $unit = array(); + $interval = array(); + $unit = array(); + $type = array(); + while ($dao->fetch()) { if (!$dao->auto_renew) { $autoRenewOption = 0; @@ -1089,9 +1092,22 @@ GROUP BY mt.member_of_contact_id"; $interval[$dao->duration_interval] = $dao->duration_interval; $unit[$dao->duration_unit] = $dao->duration_unit; + $type[$dao->id] = $dao->html_type; } - if (count($interval) == 1 && count($unit) == 1 && $autoRenewOption > 0) { + // Autorenew is only a valid option when: + // + // * Only a single membership can be chosen (i.e. a single radio + // button group) + // + // OR + // + // * There is no variation in the duration intervals or units for + // all of the relevant membership types. + $sameDuration = count($interval) == 1 && count($unit) == 1; + $singleRadioGroup = array_values($type) == array('Radio'); + + if ($sameDuration || $singleRadioGroup) { return $autoRenewOption; } else { -- 2.25.1