-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = ''; | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no spaces inside braces |
||
return $fmt->formatCurrency($value/100, "EUR"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
|
||
protected function allows($key, $value): bool | ||
|
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).