vendor/shopware/core/Checkout/Customer/Subscriber/CustomerRemoteAddressSubscriber.php line 40

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Customer\Subscriber;
  3. use Shopware\Core\Checkout\Customer\Event\CustomerLoginEvent;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. class CustomerRemoteAddressSubscriber implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * @var EntityRepositoryInterface
  11.      */
  12.     private $customerRepository;
  13.     /**
  14.      * @var RequestStack
  15.      */
  16.     private $requestStack;
  17.     /**
  18.      * @internal
  19.      */
  20.     public function __construct(
  21.         EntityRepositoryInterface $customerRepository,
  22.         RequestStack $requestStack
  23.     ) {
  24.         $this->customerRepository $customerRepository;
  25.         $this->requestStack $requestStack;
  26.     }
  27.     public static function getSubscribedEvents(): array
  28.     {
  29.         return [
  30.             CustomerLoginEvent::class => 'updateRemoteAddressByLogin',
  31.         ];
  32.     }
  33.     public function updateRemoteAddressByLogin(CustomerLoginEvent $event): void
  34.     {
  35.         $request $this->requestStack
  36.             ->getMainRequest();
  37.         if (!$request) {
  38.             return;
  39.         }
  40.         $this->customerRepository->update([
  41.             [
  42.                 'id' => $event->getCustomer()->getId(),
  43.                 'remoteAddress' => $request->getClientIp(),
  44.             ],
  45.         ], $event->getContext());
  46.     }
  47. }