From 85020e43a7c7255e4fbde7972f785d0c02d7b87d Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 4 Jun 2014 21:38:41 +1200 Subject: [PATCH] CRM-14793 this is the actual fix. we will put this on all our 4.4 sites --- CRM/Batch/Form/Entry.php | 6 ++++-- CRM/Price/BAO/PriceSet.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index 0f2ba25ef7..fabc5f5ffd 100644 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -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(); diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index 038962a740..ce9822e7e7 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -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 -- 2.25.1