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

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. /**
  8.  * @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
  9.  */
  10. class CustomerRemoteAddressSubscriber implements EventSubscriberInterface
  11. {
  12.     private EntityRepositoryInterface $customerRepository;
  13.     private RequestStack $requestStack;
  14.     /**
  15.      * @internal
  16.      */
  17.     public function __construct(
  18.         EntityRepositoryInterface $customerRepository,
  19.         RequestStack $requestStack
  20.     ) {
  21.         $this->customerRepository $customerRepository;
  22.         $this->requestStack $requestStack;
  23.     }
  24.     public static function getSubscribedEvents(): array
  25.     {
  26.         return [
  27.             CustomerLoginEvent::class => 'updateRemoteAddressByLogin',
  28.         ];
  29.     }
  30.     public function updateRemoteAddressByLogin(CustomerLoginEvent $event): void
  31.     {
  32.         $request $this->requestStack
  33.             ->getMainRequest();
  34.         if (!$request) {
  35.             return;
  36.         }
  37.         $this->customerRepository->update([
  38.             [
  39.                 'id' => $event->getCustomer()->getId(),
  40.                 'remoteAddress' => $request->getClientIp(),
  41.             ],
  42.         ], $event->getContext());
  43.     }
  44. }