pimcore / ecommerce-framework-bundle

Ecommerce Framework community bundle provides e-commerce functionality such as product listing and filtering, pricing, carts and checkouts for Pimcore.
https://pimcore.com/docs/platform/Ecommerce_Framework/
Other
8 stars 30 forks source link

[Currency] Add event for currency formatting #129

Closed mysliwietzflorian closed 10 months ago

mysliwietzflorian commented 11 months ago

Proposal: Add an event before any currency is formatted to add flexibility for the formatting patterns. Code could still be improved (Add custom event model, define event name), but do we want this change?

Our use-case is a new Swiss tenant, where two different common currency formats exist:

The change in this PR allows us to write something like inside an EventSubscriber:

$value = (string)$event->getArgument('value');
if (str_ends_with($value, '.00')) {
    $event->setArgument('pattern', '#,##0.–');
}
NiklasBr commented 11 months ago

Isn't this already possible using https://pimcore.com/docs/platform/Pimcore/Multi_Language_i18n/Formatting_Service?

mysliwietzflorian commented 11 months ago

@NiklasBr

Isn't this already possible using https://pimcore.com/docs/platform/Pimcore/Multi_Language_i18n/Formatting_Service?

Maybe I have overlooked something. As far as I have tried you can set a pattern for a locale, but you cannot have different patterns depending on the value. In my example above I use the default Swiss format, but change the pattern if a specific value occurs ('#,##0.–').

I could not figure out a way to do this. ;)

NiklasBr commented 11 months ago

There is a patthern argument you can use though.

https://github.com/pimcore/pimcore/blob/ce6cff09c03044f777f943d59ae730a6eb6cb924/lib/Localization/IntlFormatter.php#L202-L217

mysliwietzflorian commented 10 months ago

There is a patthern argument you can use though.

Agree. I see your point. That means I'd need to check before the call of formatCurrency. Should work for me. ;)