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

  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(
  18.         private readonly EntityRepository $customerRepository,
  19.         private readonly RequestStack $requestStack
  20.     ) {
  21.     }
  22.     public static function getSubscribedEvents(): array
  23.     {
  24.         return [
  25.             CustomerLoginEvent::class => 'updateRemoteAddressByLogin',
  26.         ];
  27.     }
  28.     public function updateRemoteAddressByLogin(CustomerLoginEvent $event): void
  29.     {
  30.         $request $this->requestStack
  31.             ->getMainRequest();
  32.         if (!$request) {
  33.             return;
  34.         }
  35.         $this->customerRepository->update([
  36.             [
  37.                 'id' => $event->getCustomer()->getId(),
  38.                 'remoteAddress' => $request->getClientIp(),
  39.             ],
  40.         ], $event->getContext());
  41.     }
  42. }