-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated IntegerToMoneyFormatHandler.php to fix process method #268
Updated IntegerToMoneyFormatHandler.php to fix process method #268
Conversation
Replacing money_format function in process method
@@ -28,7 +28,12 @@ public function __construct(array $allowedKeys, string $format = '%.2n') | |||
*/ | |||
protected function process($key, $value): ?string | |||
{ | |||
return money_format($this->format, $value / 100); | |||
$locale = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use LocaleContextInterface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using LocaleContextInterface
makes a lot of assumptions. I just inlined a version of this handler to an app to un-block upgrading to PHP 8 and ended up hardcoding the locale in for now because the one spot this handler gets used in our app (order export) the handler lacks the context needed to get the locale from the order, which would mean that the field would be exported in the request's active locale (and in a multi-lingual store that may not be desired).
if(isset($GLOBALS['request']) && $GLOBALS['request']) { | ||
$locale = $GLOBALS['request']->getLocale(); | ||
} | ||
$fmt = new \NumberFormatter( $locale, \NumberFormatter::CURRENCY ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$formatter
or $numberFormatter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no spaces inside braces
$locale = $GLOBALS['request']->getLocale(); | ||
} | ||
$fmt = new \NumberFormatter( $locale, \NumberFormatter::CURRENCY ); | ||
return $fmt->formatCurrency($value/100, "EUR"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EUR
should not be hardcoded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as I noted above, we don't have the context to get the right currency code to use here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, @Isabellebengrine you need to consider @andriusvo feedbacks.
Fixed in 0.23.0 |
Replacing money_format function in process method
Replaced the money_format function used in the process method to fix error when using the exporter button