$fieldParams['is_display_amounts'] = $fieldParams['is_required'] = 0;
$fieldParams['weight'] = $fieldParams['option_weight'][1] = 1;
$fieldParams['option_label'][1] = $params['name'];
- $fieldParams['option_description'][1] = $params['description'];
+ $fieldParams['option_description'][1] = CRM_Utils_Array::value('description', $params);
$fieldParams['membership_type_id'][1] = $membershipTypeId;
$fieldParams['option_amount'][1] = empty($params['minimum_fee']) ? 0 : $params['minimum_fee'];
}
}
$results['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params);
- $results['description'] = $params['description'];
+ $results['description'] = CRM_Utils_Array::value('description', $params);
CRM_Price_BAO_FieldValue::add($results, $optionsIds);
}
}
else {
$amount = 0;
}
+
+ $updateValues = array(
+ 2 => array('financial_type_id', 'financial_type_id', 'Integer'),
+ 3 => array('label', 'name', 'String'),
+ 4 => array('amount', 'minimum_fee', 'Float'),
+ 5 => array('description', 'description', 'String'),
+ );
+
+ $queryParams = array(1 => array($membershipTypeId, 'Integer'));
+ foreach ($updateValues as $key => $value) {
+ if (array_key_exists($value[1], $params)) {
+ $updateFields[] = "cpfv." . $value[0] . " = %$key";
+ if ($value[1] == 'minimum_fee') {
+ $fieldValue = $amount;
+ }
+ else {
+ $fieldValue = $params[$value[1]];
+ }
+ $queryParams[$key] = array($fieldValue, $value[2]);
+ }
+ }
+
$query = "UPDATE `civicrm_price_field_value` cpfv
INNER JOIN civicrm_price_field cpf on cpf.id = cpfv.price_field_id
INNER JOIN civicrm_price_set cps on cps.id = cpf.price_set_id
-SET cpfv.financial_type_id = %2,
-cpfv.label = %3,
-cpfv.amount = %4,
-cpfv.description = %5
-WHERE cpfv.membership_type_id = %1 AND cps.is_quick_config = 1 AND cps.name != 'default_membership_type_amount'";
- $params = array(1 => array($membershipTypeId, 'Integer'),
- 2 => array($params['financial_type_id'], 'Integer'),
- 3 => array($params['name'], 'String'),
- 4 => array($amount, 'Float'),
- 5 => array($params['description'], 'String'),
- );
- CRM_Core_DAO::executeQuery($query, $params);
+SET " . implode(' , ', $updateFields) . " WHERE cpfv.membership_type_id = %1
+AND cps.is_quick_config = 1 AND cps.name != 'default_membership_type_amount'";
+ CRM_Core_DAO::executeQuery($query, $queryParams);
}
}