Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomerNotification.php
Go to the documentation of this file.
1 <?php
7 
16 use Psr\Log\LoggerInterface;
17 
19 {
23  private $session;
24 
28  private $notificationStorage;
29 
33  private $customerRepository;
34 
38  private $state;
39 
43  private $logger;
44 
54  public function __construct(
55  Session $session,
56  NotificationStorage $notificationStorage,
57  State $state,
58  CustomerRepositoryInterface $customerRepository,
59  LoggerInterface $logger
60  ) {
61  $this->session = $session;
62  $this->notificationStorage = $notificationStorage;
63  $this->state = $state;
64  $this->customerRepository = $customerRepository;
65  $this->logger = $logger;
66  }
67 
75  {
76  $customerId = $this->session->getCustomerId();
77 
78  if ($this->state->getAreaCode() == Area::AREA_FRONTEND && $request->isPost()
79  && $this->notificationStorage->isExists(
82  )
83  ) {
84  try {
85  $customer = $this->customerRepository->getById($customerId);
86  $this->session->setCustomerData($customer);
87  $this->session->setCustomerGroupId($customer->getGroupId());
88  $this->session->regenerateId();
89  $this->notificationStorage->remove(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customer->getId());
90  } catch (NoSuchEntityException $e) {
91  $this->logger->error($e);
92  }
93  }
94  }
95 }
__construct(Session $session, NotificationStorage $notificationStorage, State $state, CustomerRepositoryInterface $customerRepository, LoggerInterface $logger)
beforeDispatch(AbstractAction $subject, RequestInterface $request)
$customer
Definition: customers.php:11
$logger
$customerRepository