CRM-14793 this is the actual fix. we will put this on all our 4.4 sites
authorEileen McNaughton <eileen@fuzion.co.nz>
Wed, 4 Jun 2014 09:38:41 +0000 (21:38 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Wed, 4 Jun 2014 09:38:41 +0000 (21:38 +1200)
CRM/Batch/Form/Entry.php
CRM/Price/BAO/PriceSet.php

index 0f2ba25ef7d04c341fd46b2dc1fe507f1b5055cd..fabc5f5ffd22c516a2750b88db626b05d9e2f528 100644 (file)
@@ -391,7 +391,9 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
     // get the price set associated with offline contribution record.
     $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_contribution_amount', 'id', 'name');
     $this->_priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
-    $fieldID = key($this->_priceSet['fields']);
+    $priceFieldID = CRM_Price_BAO_PriceSet::getOnlyPriceFieldID($this->_priceSet);
+    $priceFieldValueID = CRM_Price_BAO_PriceSet::getOnlyPriceFieldValueID($this->_priceSet);
+    $fieldID = $priceFieldID;
 
     if (isset($params['field'])) {
       foreach ($params['field'] as $key => $value) {
@@ -447,7 +449,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
         $value['skipRecentView'] = TRUE;
 
         // build line item params
-        $this->_priceSet['fields'][$fieldID]['options'][$fieldID]['amount'] =  $value['total_amount'];
+        $this->_priceSet['fields'][$fieldID]['options'][$priceFieldValueID ]['amount'] =  $value['total_amount'];
         $value['price_'.$fieldID] = 1;
 
         $lineItem = array();
index 038962a740470648ec4e104e8351272633f6202a..ce9822e7e7a5462fd574d97d4c3ddfd8487bdc7c 100644 (file)
@@ -560,6 +560,38 @@ WHERE  id = %1";
     return $setTree;
   }
 
+  /**
+   * Get the Price Field ID. We call this function when more than one being present would represent an error
+   * starting format derived from current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId))
+   * @param array $priceSet
+   *
+   * @throws CRM_Core_Exception
+   * @return int
+   */
+  static function getOnlyPriceFieldID(array $priceSet) {
+    if(count($priceSet['fields']) > 1) {
+      throw new CRM_Core_Exception(ts('expected only one price field to be in priceset but multiple are present'));
+    }
+    return (int) implode('_', array_keys($priceSet['fields']));
+  }
+
+  /**
+   * Get the Price Field Value ID. We call this function when more than one being present would represent an error
+   * current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId))
+   * @param array $priceSet
+   *
+   * @throws CRM_Core_Exception
+   * @return int
+   */
+  static function getOnlyPriceFieldValueID(array $priceSet) {
+    $priceFieldID = self::getOnlyPriceFieldID($priceSet);
+    if(count($priceSet['fields'][$priceFieldID]['options']) > 1) {
+      throw new CRM_Core_Exception(ts('expected only one price field to be in priceset but multiple are present'));
+    }
+    return (int) implode('_', array_keys($priceSet['fields'][$priceFieldID]['options']));
+  }
+
+
   /**
    * @param CRM_Core_Form $form
    * @param $id