Closed samhibberd closed 4 years ago
I’m not able to reproduce this, but appears to be a Yii bug with isNormalizedValueMispresented()
. Can be worked around by casting the value to a float, or passing the $currency
argument.
@brandonkelly this one has cropped up again for me, I did some digging in the Yii slack channel and feedback suggested it could well be a configuration issue.
I have narrowed it down to decimal strings as it only throws the exception if passed a string with decimal '26.4'
passing '26'
without the decimal and it's all good.
And if I override the configuration (just using the example in the Yii docs) then the issue goes away, https://www.yiiframework.com/doc/guide/2.0/en/output-formatting#configuring-formatter
The formatter config is provided by the locale, so not something we can tweak.
It doesn't look like the locale config is setting a currencyCode
with \Yii::$app->getFormatter()->currencyCode
returning null
.
Should the locale not be setting that?
We do in fact set that, if the Intl extension is not installed. Otherwise it’s not needed since the Intl extension will handle it automatically. Just tested and works as expected on my end.
What locale is your site set to? Most locales don’t actually specify a currency. en-GB
does, though.
Set to en-GB
Maybe something is wrong with your Intl extension, then.
It was, finally had a chance to get everything updated locally and all resolved, thanks.
Description
Running into an odd error (reported in the commerce repo https://github.com/craftcms/commerce/issues/1541) but it think it might be an issue with the core.
Looks to be caused when a string rather than float / number is passed to the currency formatter:
Craft::$app->getFormatter()->asCurrency('26.3')
Throws:
The default currency code for the formatter is not defined.
Error suggests the config exception is thrown from the
asCurrencyStringFallback()
Steps to reproduce
Additional info