diff --git a/src/fields/Money.php b/src/fields/Money.php index fc366ca22dc..25525834b50 100644 --- a/src/fields/Money.php +++ b/src/fields/Money.php @@ -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); } } @@ -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(); }