From 1692ea4fa5114403bd34eff6f56e18b3b570af33 Mon Sep 17 00:00:00 2001
From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com>
Date: Sat, 14 Sep 2024 12:48:02 +0100
Subject: [PATCH] Minor fix
Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com>
---
app/system/helpers/country_helper.php | 4 ++--
app/system/libraries/Country.php | 11 ++++++-----
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/app/system/helpers/country_helper.php b/app/system/helpers/country_helper.php
index 865456b9e5..2ae9a9f82d 100644
--- a/app/system/helpers/country_helper.php
+++ b/app/system/helpers/country_helper.php
@@ -5,9 +5,9 @@
*/
if (!function_exists('format_address')) {
- function format_address($address, $useLineBreaks = true)
+ function format_address($address, $useLineBreaks = true, $useDefaultFormat = false)
{
- return Country::addressFormat($address, $useLineBreaks);
+ return Country::addressFormat($address, $useLineBreaks, $useDefaultFormat);
}
}
diff --git a/app/system/libraries/Country.php b/app/system/libraries/Country.php
index 10476e8c60..5ef6f47826 100644
--- a/app/system/libraries/Country.php
+++ b/app/system/libraries/Country.php
@@ -28,7 +28,7 @@ class Country
protected $countriesCollection = [];
- public function addressFormat($address, $useLineBreaks = true)
+ public function addressFormat($address, $useLineBreaks = true, $useDefaultFormat = false)
{
$format = $this->getDefaultFormat();
@@ -38,6 +38,9 @@ public function addressFormat($address, $useLineBreaks = true)
if (!empty($address['format']))
$format = $address['format'];
+ if ($useDefaultFormat)
+ $format = $this->defaultFormat;
+
$formattedAddress = str_replace(['\r\n', '\r', '\n'], '
',
preg_replace(['/\s\s+/', '/\r\r+/', '/\n\n+/'], '
',
trim(str_replace([
@@ -110,8 +113,7 @@ protected function evalAddress($address)
foreach ($this->requiredAddressKeys as $key) {
if ($key == 'country') {
$this->processCountryValue($address[$key], $result);
- }
- else {
+ } else {
$result[$key] = $address[$key] ?? '';
}
}
@@ -124,8 +126,7 @@ protected function processCountryValue($country, &$result)
if (!is_string($country) && isset($country['country_name'])) {
$result['country'] = $country['country_name'];
$result['format'] = $country['format'];
- }
- elseif (is_numeric($country)) {
+ } elseif (is_numeric($country)) {
$this->loadCountries();
if ($countryModel = $this->countriesCollection->find($country)) {