From 5da7cc4936ccca8b8cfaac4c8880da9b1a58261e Mon Sep 17 00:00:00 2001 From: Mathieu Lutfy Date: Wed, 9 Dec 2020 09:28:25 -0500 Subject: [PATCH] dev/core#1019 Fix currency formatting of Total Amount on Event and Contribution pages (with multi-currency form support) --- CRM/Contribute/Form/Contribution/Main.php | 7 +++++++ CRM/Event/Form/Registration/Register.php | 9 +++++++++ templates/CRM/Price/Form/Calculate.tpl | 13 ++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 6ff333e145..fa76918ee7 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -58,6 +58,13 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu $this->assign('isShare', CRM_Utils_Array::value('is_share', $this->_values)); $this->assign('isConfirmEnabled', CRM_Utils_Array::value('is_confirm_enabled', $this->_values)); + // Required for currency formatting in the JS layer + // this is a temporary fix intended to resolve a regression quickly + // And assigning moneyFormat for js layer formatting + // will only work until that is done. + // https://github.com/civicrm/civicrm-core/pull/19151 + $this->assign('moneyFormat', CRM_Utils_Money::format(1234.56)); + $this->assign('reset', CRM_Utils_Request::retrieve('reset', 'Boolean')); $this->assign('mainDisplay', CRM_Utils_Request::retrieve('_qf_Main_display', 'Boolean', CRM_Core_DAO::$_nullObject)); diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index 423f635d8d..cc88542e02 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -319,6 +319,15 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { // CRM-18399: used by template to pass pre profile id as a url arg $this->assign('custom_pre_id', $this->_values['custom_pre_id']); + // Required for currency formatting in the JS layer + + // Required for currency formatting in the JS layer + // this is a temporary fix intended to resolve a regression quickly + // And assigning moneyFormat for js layer formatting + // will only work until that is done. + // https://github.com/civicrm/civicrm-core/pull/19151 + $this->assign('moneyFormat', CRM_Utils_Money::format(1234.56)); + CRM_Core_Payment_ProcessorForm::buildQuickForm($this); $contactID = $this->getContactID(); diff --git a/templates/CRM/Price/Form/Calculate.tpl b/templates/CRM/Price/Form/Calculate.tpl index dab6017c01..170334b499 100644 --- a/templates/CRM/Price/Form/Calculate.tpl +++ b/templates/CRM/Price/Form/Calculate.tpl @@ -31,6 +31,11 @@ var thousandMarker = '{/literal}{$config->monetaryThousandSeparator}{literal}'; var separator = '{/literal}{$config->monetaryDecimalPoint}{literal}'; var symbol = '{/literal}{$currencySymbol}{literal}'; +// moneyFormat is part of a temporary fix. it should +// not be expected to be present in future versions +// see https://github.com/civicrm/civicrm-core/pull/19151 + +var moneyFormat = '{/literal}{$moneyFormat}{literal}'; var optionSep = '|'; // Recalculate the total fees based on user selection @@ -161,7 +166,13 @@ function display(totalfee) { // totalfee is monetary, round it to 2 decimal points so it can // go as a float - CRM-13491 totalfee = Math.round(totalfee*100)/100; - var totalFormattedFee = symbol + ' ' + CRM.formatMoney(totalfee, true); + // dev/core#1019 Use the moneyFormat assigned to the template as an interim fix + // to support forms using a currency other that the site default. Also make sure to + // support various currency formatting options, + // temporary measure - pending + // our preferred fix. + // see https://github.com/civicrm/civicrm-core/pull/19151 + var totalFormattedFee = CRM.formatMoney(totalfee, false, moneyFormat); cj('#pricevalue').html(totalFormattedFee); cj('#total_amount').val( totalfee ); -- 2.25.1