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

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