Files
2025-08-02 16:30:27 +02:00

46 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace External\ZNZBundle\EventSubscriber;
use External\ZNZBundle\Util\ZNZPriceLevelsGenerator;
use KupShop\OrderingBundle\Event\OrderEvent;
use KupShop\UserBundle\Event\UserRegisteredEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class UserSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly ZNZPriceLevelsGenerator $priceLevelsGenerator,
) {
}
public static function getSubscribedEvents(): array
{
return [
UserRegisteredEvent::class => [
['updateUserPriceLevel', 200],
],
OrderEvent::ORDER_FINISHED => [
['updateUserPriceLevel', 200],
],
];
}
public function updateUserPriceLevel(UserRegisteredEvent|OrderEvent $event): void
{
if ($event instanceof UserRegisteredEvent) {
$userId = $event->getUser()->id;
} else {
$userId = $event->getOrder()->id_user;
}
if (empty($userId)) {
return;
}
$this->priceLevelsGenerator->generate((int) $userId);
}
}