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

[Currency] Add event for currency formatting #129

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Model/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -32,6 +34,8 @@

const USE_NAME = 'longname';

protected EventDispatcherInterface $eventDispatcher;

protected string $currencyShortName;

protected string $currencySymbol;
Expand Down Expand Up @@ -65,6 +69,7 @@
public function __construct(string $currencyShortName)
{
$this->currencyShortName = $currencyShortName;
$this->eventDispatcher = \Pimcore::getContainer()->get('event_dispatcher');
}

protected function getFormatter(): IntlFormatter
Expand All @@ -89,6 +94,14 @@
$value = $value->asString();
}

$event = new GenericEvent($value, [
'value' => $value,
'pattern' => $pattern,
]);
$this->eventDispatcher->dispatch($event, 'ecommerce.on-currency-formatted');

Check failure on line 101 in src/Model/Currency.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.1, lowest, false)

Method Psr\EventDispatcher\EventDispatcherInterface::dispatch() invoked with 2 parameters, 1 required.

Check failure on line 101 in src/Model/Currency.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2, highest, 11.x-dev as 11.0.0, true)

Method Psr\EventDispatcher\EventDispatcherInterface::dispatch() invoked with 2 parameters, 1 required.
$value = $event->getArgument('value');
$pattern = $event->getArgument('pattern');

return $this->getFormatter()->formatCurrency($value, $this->currencyShortName, $pattern);
}

Expand Down
Loading