From f59ca3b0c449dd22b02a88a84aa37039efef53dc 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 | 3 +++ CRM/Event/Form/Registration/Register.php | 3 +++ templates/CRM/Price/Form/Calculate.tpl | 6 +++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 6ff333e145f9..187c6a6941f7 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -58,6 +58,9 @@ public function preProcess() { $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->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 423f635d8d58..1e78229ee87e 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -319,6 +319,9 @@ public function buildQuickForm() { // 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 + $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 dab6017c0150..64fff0cf4d61 100644 --- a/templates/CRM/Price/Form/Calculate.tpl +++ b/templates/CRM/Price/Form/Calculate.tpl @@ -31,6 +31,7 @@ var thousandMarker = '{/literal}{$config->monetaryThousandSeparator}{literal}'; var separator = '{/literal}{$config->monetaryDecimalPoint}{literal}'; var symbol = '{/literal}{$currencySymbol}{literal}'; +var moneyFormat = '{/literal}{$moneyFormat}{literal}'; var optionSep = '|'; // Recalculate the total fees based on user selection @@ -161,7 +162,10 @@ 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, to support + // forms using a currency other that the site default. Also make sure to + // support various currency formatting options, supported by formatMoney. + var totalFormattedFee = CRM.formatMoney(totalfee, false, moneyFormat); cj('#pricevalue').html(totalFormattedFee); cj('#total_amount').val( totalfee );