CRM-16867 use consolidated function to prevent code duplicateion
authorEileen McNaughton <eileen@fuzion.co.nz>
Sun, 19 Jul 2015 09:54:02 +0000 (21:54 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Wed, 22 Jul 2015 06:38:53 +0000 (18:38 +1200)
This patch keeps existing functionality working - but I believe existing functionality is wrong as the price set uses Radio buttons so it
is NOT possible to use both types of membership in 1 transaction

CRM/Member/Form/MembershipBlock.php
CRM/Price/BAO/PriceSet.php

index af6a018766dcb368c6492983285c033da5407b92..73a8cb254f528efa72b76d67fb24b8723c878f42 100644 (file)
@@ -231,7 +231,7 @@ class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPa
 
     if (!empty($params['member_price_set_id'])) {
       //check if this price set has membership type both auto-renew and non-auto-renew memberships.
-      $bothTypes = CRM_Price_BAO_PriceSet::checkMembershipPriceSet($params['member_price_set_id']);
+      $bothTypes = CRM_Price_BAO_PriceSet::isMembershipPriceSetContainsMixOfRenewNonRenew($params['member_price_set_id']);
 
       //check for supporting payment processors
       //if both auto-renew and non-auto-renew memberships
index 47d3b9a13d2c1d42b547ab2462dbfa2fadfdda1f..48278330095b385145bc6831c3686b5ff50ea335 100644 (file)
@@ -1382,41 +1382,16 @@ GROUP BY     mt.member_of_contact_id";
   }
 
   /**
-   * Check if price set id provides option for
-   * user to select both auto-renew and non-auto-renew memberships
+   * Check if price set id provides option for user to select both auto-renew and non-auto-renew memberships
    *
    * @param int $id
    *
    * @return bool
    */
-  public static function checkMembershipPriceSet($id) {
-    $query
-      = "SELECT      pfv.id, pfv.price_field_id, pfv.name, pfv.membership_type_id, pf.html_type, mt.auto_renew
-FROM        civicrm_price_field_value pfv
-LEFT JOIN   civicrm_price_field pf ON pf.id = pfv.price_field_id
-LEFT JOIN   civicrm_price_set ps ON ps.id = pf.price_set_id
-LEFT JOIN   civicrm_membership_type mt ON mt.id = pfv.membership_type_id
-WHERE       ps.id = %1
-";
-
-    $params = array(1 => array($id, 'Integer'));
-    $dao = CRM_Core_DAO::executeQuery($query, $params);
-
-    $autoRenew = array();
-    //FIXME: do a comprehensive check of whether
-    //2 membership types can be selected
-    //instead of comparing all of them
-    while ($dao->fetch()) {
-      //temp fix for #CRM-10370
-      //if its NULL consider it '0' i.e. 'No auto-renew option'
-      $daoAutoRenew = $dao->auto_renew;
-      if ($daoAutoRenew === NULL) {
-        $daoAutoRenew = 0;
-      }
-      if (!empty($autoRenew) && !in_array($daoAutoRenew, $autoRenew)) {
-        return TRUE;
-      }
-      $autoRenew[] = $daoAutoRenew;
+  public static function isMembershipPriceSetContainsMixOfRenewNonRenew($id) {
+    $membershipTypes = self::getMembershipTypesFromPriceSet($id);
+    if (!empty($membershipTypes['autorenew']) && !empty($membershipTypes['non_renew'])) {
+      return TRUE;
     }
     return FALSE;
   }