CRM-18305 - CiviMember - Auto-renew checkbox option was being displayed multiple...
authorAllen Shaw <allen@JoineryHQ.com>
Thu, 31 Mar 2016 21:19:21 +0000 (16:19 -0500)
committerAllen Shaw <allen@JoineryHQ.com>
Thu, 31 Mar 2016 21:19:21 +0000 (16:19 -0500)
With support for contribution pages with and without price sets.

CRM/Price/BAO/PriceSet.php
templates/CRM/Price/Form/PriceSet.tpl

index 67c8ab4dc905b479929aba7babbf48114c0564c7..c9a485a653fd2f27d2d0e3c9a15b1234cae2823f 100644 (file)
@@ -1056,6 +1056,29 @@ WHERE  id = %1";
     if ($className == 'CRM_Contribute_Form_Contribution_Main') {
       $form->_quickConfig = $quickConfig;
     }
+
+    // Mark which field should have the auto-renew checkbox, if any. CRM-18305
+    if (is_array($form->_membershipTypeValues)) {
+      $autoRenewMembershipTypes = array();
+      foreach ($form->_membershipTypeValues as $membershiptTypeValue) {
+        if ($membershiptTypeValue['auto_renew']) {
+          $autoRenewMembershipTypes[] = $membershiptTypeValue['id'];
+        }
+      }
+      foreach ($form->_priceSet['fields'] as &$field) {
+        if (array_key_exists('options', $field) && is_array($field['options'])) {
+          foreach ($field['options'] as $option) {
+            if ($option['membership_type_id']) {
+              if (in_array($option['membership_type_id'], $autoRenewMembershipTypes)) {
+                $form->_priceSet['auto_renew_membership_field'] = $field['id'];
+                // Only one field can offer auto_renew memberships, so break here.
+                break;
+              }
+            }
+          }
+        }
+      }
+    }
     $form->assign('priceSet', $form->_priceSet);
 
     $component = 'contribution';
index 86a70d95d93ffad976ec9c5096b4443fcb7b2fc4..e717726749fc3b6c0dd9a0219737fe351a1e24c5 100644 (file)
                 </div>
 
             {/if}
-              {if !empty($extends) && $extends eq "Membership" && $element.name == 'membership_amount'}
-                <div id="allow_auto_renew">
-                  <div class='crm-section auto-renew'>
-                    <div class='label'></div>
-                    <div class ='content'>
-                      {if isset($form.auto_renew) }
-                        {$form.auto_renew.html}&nbsp;{$form.auto_renew.label}
-                      {/if}
+              {if !empty($extends) && $extends eq "Membership"}
+                {if (!empty($priceSet) && $element.id == $priceSet.auto_renew_membership_field) || (empty($priceSet) && $element.name == 'membership_amount')}
+                  <div id="allow_auto_renew">
+                    <div class='crm-section auto-renew'>
+                      <div class='label'></div>
+                      <div class ='content'>
+                        {if isset($form.auto_renew) }
+                          {$form.auto_renew.html}&nbsp;{$form.auto_renew.label}
+                        {/if}
+                      </div>
                     </div>
                   </div>
-                </div>
+                {/if}
               {/if}
               <div class="clear"></div>
           </div>