Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Sep 14, 2024
1 parent e659175 commit 1692ea4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/system/helpers/country_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
11 changes: 6 additions & 5 deletions app/system/libraries/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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'], '<br />',
preg_replace(['/\s\s+/', '/\r\r+/', '/\n\n+/'], '<br />',
trim(str_replace([
Expand Down Expand Up @@ -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] ?? '';
}
}
Expand All @@ -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)) {
Expand Down

0 comments on commit 1692ea4

Please sign in to comment.