custom/plugins/NetiNextAccessManager/src/Subscriber/MailSubscriber.php line 31

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace NetInventors\NetiNextAccessManager\Subscriber;
  4. use NetInventors\NetiNextAccessManager\Events\BusinessEvent\CustomerRegisteredOperatorEvent;
  5. use NetInventors\NetiNextAccessManager\Service\Repository\CustomerMediaRepository;
  6. use Shopware\Core\Content\MailTemplate\Service\Event\MailBeforeValidateEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class MailSubscriber implements EventSubscriberInterface
  9. {
  10.     private string                  $customerId '';
  11.     private CustomerMediaRepository $customerUploadFilesRepository;
  12.     public function __construct(CustomerMediaRepository $customerUploadFilesRepository)
  13.     {
  14.         $this->customerUploadFilesRepository $customerUploadFilesRepository;
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             MailBeforeValidateEvent::class         => 'onMailBeforeValidate',
  20.             CustomerRegisteredOperatorEvent::class => 'onOperatorMailEvent',
  21.         ];
  22.     }
  23.     public function onOperatorMailEvent(CustomerRegisteredOperatorEvent $event): void
  24.     {
  25.         $this->customerId $event->getCustomer()->getId();
  26.     }
  27.     public function onMailBeforeValidate(MailBeforeValidateEvent $event): void
  28.     {
  29.         if ('' === $this->customerId) {
  30.             return;
  31.         }
  32.         $files $this->customerUploadFilesRepository->getUploadFilesIdsFromCustomer(
  33.             $this->customerId,
  34.             $event->getContext()
  35.         );
  36.         $event->addData('mediaIds'$files);
  37.         $this->customerId '';
  38.     }
  39. }