Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Aug 21, 2024
1 parent e3ed82c commit b5e54e8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/fields/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function __construct($config = [])
if (isset($config[$name])) {
// at this point the currency property isn't set yet, so we need to explicitly pass it to the _normalizeNumber()
// see https://github.com/craftcms/cms/issues/15565 for more details
$config[$name] = $this->_normalizeNumber($config[$name], $config['currency']);
$config[$name] = $this->_normalizeNumber($config[$name], $config['currency'] ?? null);
}
}

Expand Down Expand Up @@ -220,18 +220,20 @@ private function _normalizeNumber(mixed $value, ?string $currency = null): ?stri
return null;
}

$currency ??= $this->currency;

// Was this submitted with a locale ID? (This means the data is coming from the settings form)
if (isset($value['locale'], $value['value'])) {
if ($value['value'] === '') {
return null;
}

$value['currency'] = $currency ?? $this->currency;
$value['currency'] = $currency;
$money = MoneyHelper::toMoney($value);
return $money ? $money->getAmount() : null;
}

$money = new MoneyLibrary($value, new Currency($currency ?? $this->currency));
$money = new MoneyLibrary($value, new Currency($currency));
return $money->getAmount();
}

Expand Down

0 comments on commit b5e54e8

Please sign in to comment.