BIG HACK: Corrected frequency calculation for new members
authorRuben Rodriguez <ruben@fsf.org>
Mon, 12 Mar 2018 23:47:35 +0000 (19:47 -0400)
committerRuben Rodriguez <ruben@fsf.org>
Mon, 12 Mar 2018 23:47:35 +0000 (19:47 -0400)
CRM/Contribute/Form/ContributionBase.php
CRM/Price/BAO/PriceSet.php

index 78d7fb396f74a314bd6961290f378ffe811da09c..492acb0a5250f2f3ec6ae152ea7c6491972876e4 100644 (file)
@@ -1321,7 +1321,14 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
       $this->_params['is_recur'] = $this->_values['is_recur'] = 1;
       // check if price set is not quick config
       if (!empty($this->_params['priceSetId']) && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params['priceSetId'], 'is_quick_config')) {
-        list($this->_params['frequency_interval'], $this->_params['frequency_unit']) = CRM_Price_BAO_PriceSet::getRecurDetails($this->_params['priceSetId']);
+
+        // based on Lisa's commit 520680c63f7b886643e80c2400d9e9b6f1a1fd52
+        // Extract the ids for all of the line items that have been chosen.
+        $priceFieldValueIds = array_keys($this->_lineItem[$this->_params['priceSetId']])[0];
+        if (empty($priceFieldValueIds))
+          $priceFieldValueIds = array_keys($this->_params['price_126'])[0];
+        list($this->_params['frequency_interval'], $this->_params['frequency_unit']) = CRM_Price_BAO_PriceSet::getRecurDetails($this->_params['priceSetId'], $priceFieldValueIds);
+        //list($this->_params['frequency_interval'], $this->_params['frequency_unit']) = CRM_Price_BAO_PriceSet::getRecurDetails($this->_params['priceSetId']);
       }
       else {
         // FIXME: set interval and unit based on selected membership type
index f6dfec5c34b33c63961b51852868edde7369f13f..97dbb069b37d1c78fb5207db1fdc7063d5134308 100644 (file)
@@ -1451,13 +1451,14 @@ GROUP BY     mt.member_of_contact_id ";
    * @return array
    *   associate array of frequency interval and unit
    */
-  public static function getRecurDetails($priceSetId) {
+  public static function getRecurDetails($priceSetId, $priceFieldValueIds) {
 
     $query = 'SELECT mt.duration_interval, mt.duration_unit
             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
-            WHERE pf.price_set_id = %1 LIMIT 1';
+            WHERE pf.price_set_id = %1 AND pfv.id = '
+            . $priceFieldValueIds . ' LIMIT 1';
 
     $params = array(1 => array($priceSetId, 'Integer'));
     $dao = CRM_Core_DAO::executeQuery($query, $params);