From 191fe5232fab890ca8a8b6e59cd7eee94060ff8c Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 16 Sep 2022 07:53:24 -0400 Subject: [PATCH] SearchKit - Update to newer money formatting function --- .../Api4/Action/SearchDisplay/AbstractRunAction.php | 3 ++- .../phpunit/api/v4/SearchDisplay/SearchRunTest.php | 12 ++++++------ release-notes/5.18.0.md | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php b/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php index 1dfb5d75d0..ff47e6d8d1 100644 --- a/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php +++ b/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php @@ -775,7 +775,8 @@ abstract class AbstractRunAction extends \Civi\Api4\Generic\AbstractAction { case 'Money': $currencyField = $this->getCurrencyField($key); - $formatted = \CRM_Utils_Money::format($rawValue, $data[$currencyField] ?? NULL); + $currency = is_string($data[$currencyField] ?? NULL) ? $data[$currencyField] : NULL; + $formatted = \Civi::format()->money($rawValue, $currency); break; case 'Date': diff --git a/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchRunTest.php b/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchRunTest.php index b7f3e9d251..a3e7c7d41d 100644 --- a/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchRunTest.php +++ b/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchRunTest.php @@ -1389,13 +1389,13 @@ class SearchRunTest extends Api4TestBase implements TransactionalInterface { // Currency should have been fetched automatically and used to format the value $this->assertEquals('GBP', $result[0]['data']['currency']); - $this->assertEquals('£ 100.00', $result[0]['columns'][0]['val']); + $this->assertEquals('£100.00', $result[0]['columns'][0]['val']); $this->assertEquals('USD', $result[1]['data']['currency']); - $this->assertEquals('$ 200.00', $result[1]['columns'][0]['val']); + $this->assertEquals('$200.00', $result[1]['columns'][0]['val']); $this->assertEquals('JPY', $result[2]['data']['currency']); - $this->assertEquals('¥ 500.00', $result[2]['columns'][0]['val']); + $this->assertEquals('¥500', $result[2]['columns'][0]['val']); // Now do a search for the contribution line-items $params['savedSearch'] = [ @@ -1412,13 +1412,13 @@ class SearchRunTest extends Api4TestBase implements TransactionalInterface { // An automatic join should have been added to fetch the contribution currency $this->assertEquals('GBP', $result[0]['data']['contribution_id.currency']); - $this->assertEquals('£ 100.00', $result[0]['columns'][0]['val']); + $this->assertEquals('£100.00', $result[0]['columns'][0]['val']); $this->assertEquals('USD', $result[1]['data']['contribution_id.currency']); - $this->assertEquals('$ 200.00', $result[1]['columns'][0]['val']); + $this->assertEquals('$200.00', $result[1]['columns'][0]['val']); $this->assertEquals('JPY', $result[2]['data']['contribution_id.currency']); - $this->assertEquals('¥ 500.00', $result[2]['columns'][0]['val']); + $this->assertEquals('¥500', $result[2]['columns'][0]['val']); } } diff --git a/release-notes/5.18.0.md b/release-notes/5.18.0.md index 03ff156b4f..a8ce0ed811 100644 --- a/release-notes/5.18.0.md +++ b/release-notes/5.18.0.md @@ -259,7 +259,7 @@ Released October 2, 2019 ([dev/core#1188](https://lab.civicrm.org/dev/core/issues/1188): [15043](https://github.com/civicrm/civicrm-core/pull/15043))** - Ensures that the Psalm Autoloader can find `CiviCRM_API3_Exception`. + Ensures that the Psalm Autoloader can find `CRM_Core_Exception`. - **File attachment uploads - pptx issue ([dev/core#1190](https://lab.civicrm.org/dev/core/issues/1190): -- 2.25.1