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

[5.x]: Currency Formatting on …DiscountAsCurrency #3816

Closed
sandrodunkel opened this issue Dec 16, 2024 · 5 comments
Closed

[5.x]: Currency Formatting on …DiscountAsCurrency #3816

sandrodunkel opened this issue Dec 16, 2024 · 5 comments

Comments

@sandrodunkel
Copy link

What happened?

Description

I am using Craft/Craft Commerce headless. All Commerce pricing values that feature the currency format the currency and value the same. e.g. storedTotalPriceAsCurrency returns "CHF 100.00" – so currency, space, value. An issue arises with negative values, probably most commonly used in the discount values, e.g. storedTotalDiscountAsCurrency, which returns CHF-100.00, so currency, NO space, value.

Steps to reproduce

  1. Use Commerce in a headless project (don't know if regular usage also has this problem)
  2. Use a negative pricing value in any …AsCurrency property (e.g. storedTotalDiscountAsCurrency)

Expected behavior

Negative values are returned the same as positive values, meaning currency – space – value.
Example positive value: CHF 100.00
Example negative value: CHF -100.00

Actual behavior

Negative values are formatted differently than positive values.
Example positive value: CHF 100.00 (with space, correct way)
Example negative value: CHF-100.00 (no space, wrong way)

Craft CMS version

Craft Pro 5.5.0

Craft Commerce version

5.2.6

PHP version

8.2.20

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

Copy link

linear bot commented Dec 16, 2024

@nfourtythree
Copy link
Contributor

Hi @sandrodunkel

Thank you for your message. Just looking into this, what formatting locale is running when you are seeing this issue?

I tried a few different ones and the results I saw were -CHF 123.45, -123,45 CHF and -123.45 CHF.

Thanks!

@sandrodunkel
Copy link
Author

Hey @nfourtythree – I'm using de-CH (German in Switzerland). The correct way here it would be CHF -123.45. This change should affect all in Craft available locales from Switzerland (de-CH, fr-CH, it-CH, en-CH).

@nfourtythree nfourtythree self-assigned this Jan 9, 2025
@nfourtythree
Copy link
Contributor

Hi @sandrodunkel

I have been digging into this and I think it is comes down to PHP's Intl extension. But would like to get some further data to confirm.

Are you able to run the following CLI command and let me know the output.

craft exec/exec "echo \craft\commerce\helpers\Currency::formatAsCurrency(-123.45, 'CHF');"

Maybe try this in your local development environment as well as production/staging.

Thanks!

@nfourtythree
Copy link
Contributor

Hi @sandrodunkel

We are going to close this issue for now as it has gone a little stale.

In terms of how the code works the formatting of the output is, at the base level, handled by PHP's Intl extension. So it would seem like maybe a version issue with that.

Let me know when you have had a chance to run the command mentioned in the previous comment and we can potentially reopen the issue and investigate further.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants