Skip to content
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

Conversation

Isabellebengrine
Copy link

Replacing money_format function in process method

Q A
Bug fix? yes
New feature? no
BC breaks? no
Fixed tickets #260

Replaced the money_format function used in the process method to fix error when using the exporter button

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 = '';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use LocaleContextInterface

Copy link
Contributor

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 );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$formatter or $numberFormatter

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");

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

Copy link
Contributor

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.

Copy link
Member

@oallain oallain left a 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.

@vasilvestre vasilvestre mentioned this pull request Oct 10, 2022
@oallain
Copy link
Member

oallain commented Jan 3, 2023

Fixed in 0.23.0

@oallain oallain closed this Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants