Skip to content

Commit

Permalink
dev/core#1603 fix tangental bug on form handling of long options
Browse files Browse the repository at this point in the history
This fixes the bug that derailed the fix for https://lab.civicrm.org/dev/core/-/issues/1603

On further testing I agree with Jitendra that the price field form was mis-saving the longer values (I only
tested with Euro style decimal separators but maybe on both) and it was bad data caused by this
that made the merged fix look like a regression.

I also observed that the Money functions intended to round only appeared to since it was rounding
just fine to 2 places, as tested, but it was still rounding to 2 places when we wanted more.

This fixes both the New Price field screen (when options are entered) and the edit options screen
  • Loading branch information
eileenmcnaughton committed Sep 8, 2020
1 parent 270761f commit 09e6f54
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CRM/Price/Form/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,9 @@ public function postProcess() {
// store the submitted values in an array
$params = $this->controller->exportValues('Field');
$params['price'] = CRM_Utils_Rule::cleanMoney($params['price']);
foreach ($params['option_amount'] as $key => $amount) {
$params['option_amount'][$key] = CRM_Utils_Rule::cleanMoney($amount);
}

$params['is_display_amounts'] = CRM_Utils_Array::value('is_display_amounts', $params, FALSE);
$params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE);
Expand Down
4 changes: 3 additions & 1 deletion CRM/Price/Form/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public function setDefaultValues() {

// fix the display of the monetary value, CRM-4038
foreach ($this->_moneyFields as $field) {
// @todo use formatLocaleNumericRoundedByOptionalPrecision - but note that there is an issue where php doesn't handle
// money strings beyond a certain total length - per https://github.com/civicrm/civicrm-core/pull/18409
// & https://github.com/civicrm/civicrm-core/pull/18409
$defaults[$field] = CRM_Utils_Money::format(CRM_Utils_Array::value($field, $defaults), NULL, '%a');
}
}
Expand Down Expand Up @@ -326,7 +329,6 @@ public function postProcess() {
return NULL;
}
else {
$params = $ids = [];
$params = $this->controller->exportValues('Option');
$fieldLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $this->_fid, 'label');

Expand Down

0 comments on commit 09e6f54

Please sign in to comment.