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

  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\EntityRepository;
  5. use Shopware\Core\Framework\Log\Package;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpFoundation\RequestStack;
  8. /**
  9.  * @internal
  10.  */
  11. #[Package('customer-order')]
  12. class CustomerRemoteAddressSubscriber implements EventSubscriberInterface
  13. {
  14.     /**
  15.      * @internal
  16.      */
  17.     public function __construct(private readonly EntityRepository $customerRepository, private readonly RequestStack $requestStack)
  18.     {
  19.     }
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             CustomerLoginEvent::class => 'updateRemoteAddressByLogin',
  24.         ];
  25.     }
  26.     public function updateRemoteAddressByLogin(CustomerLoginEvent $event): void
  27.     {
  28.         $request $this->requestStack
  29.             ->getMainRequest();
  30.         if (!$request) {
  31.             return;
  32.         }
  33.         $this->customerRepository->update([
  34.             [
  35.                 'id' => $event->getCustomer()->getId(),
  36.                 'remoteAddress' => $request->getClientIp(),
  37.             ],
  38.         ], $event->getContext());
  39.     }
  40. }