From e0fdea832eb29c7ceb43f89a6f0a5f00c902361d Mon Sep 17 00:00:00 2001 From: Florian Mysliwietz Date: Mon, 9 Oct 2023 16:34:22 +0200 Subject: [PATCH] [Currency] Add event for currency formatting --- src/Model/Currency.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Model/Currency.php b/src/Model/Currency.php index cfd5832b..8a61d94b 100644 --- a/src/Model/Currency.php +++ b/src/Model/Currency.php @@ -17,6 +17,8 @@ use Pimcore\Bundle\EcommerceFrameworkBundle\Type\Decimal; use Pimcore\Localization\IntlFormatter; +use Psr\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\GenericEvent; class Currency { @@ -32,6 +34,8 @@ class Currency const USE_NAME = 'longname'; + protected EventDispatcherInterface $eventDispatcher; + protected string $currencyShortName; protected string $currencySymbol; @@ -65,6 +69,7 @@ class Currency public function __construct(string $currencyShortName) { $this->currencyShortName = $currencyShortName; + $this->eventDispatcher = \Pimcore::getContainer()->get('event_dispatcher'); } protected function getFormatter(): IntlFormatter @@ -89,6 +94,14 @@ public function toCurrency(null|float|int|string|Decimal $value, array|string $p $value = $value->asString(); } + $event = new GenericEvent($value, [ + 'value' => $value, + 'pattern' => $pattern, + ]); + $this->eventDispatcher->dispatch($event, 'ecommerce.on-currency-formatted'); + $value = $event->getArgument('value'); + $pattern = $event->getArgument('pattern'); + return $this->getFormatter()->formatCurrency($value, $this->currencyShortName, $pattern); }