Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateCustomerCookiesObserver.php
Go to the documentation of this file.
1 <?php
7 
9 
14 {
21 
28 
35  public function __construct(
36  \Magento\Persistent\Helper\Session $persistentSession,
37  \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
38  ) {
39  $this->_persistentSession = $persistentSession;
40  $this->customerRepository = $customerRepository;
41  }
42 
49  public function execute(\Magento\Framework\Event\Observer $observer)
50  {
51  if (!$this->_persistentSession->isPersistent()) {
52  return;
53  }
54 
55  $customerCookies = $observer->getEvent()->getCustomerCookies();
56  if ($customerCookies instanceof \Magento\Framework\DataObject) {
57  $persistentCustomer = $this->customerRepository->getById(
58  $this->_persistentSession->getSession()->getCustomerId()
59  );
60  $customerCookies->setCustomerId($persistentCustomer->getId());
61  $customerCookies->setCustomerGroupId($persistentCustomer->getGroupId());
62  }
63  }
64 }
$persistentSession
Definition: persistent.php:11
__construct(\Magento\Persistent\Helper\Session $persistentSession, \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository)