// 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) {
$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();
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