mirror of
https://github.com/bdnugget/magento2.git
synced 2026-11-07 17:27:36 +00:00
- removed @since 2.0.0 as it is a base release - updated version in @since and @deprecated tag taking into account all patch releases
65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* Copyright © Magento, Inc. All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
namespace Magento\Persistent\Observer;
|
|
|
|
use Magento\Framework\Event\ObserverInterface;
|
|
|
|
/**
|
|
* Class UpdateCustomerCookies
|
|
*/
|
|
class UpdateCustomerCookiesObserver implements ObserverInterface
|
|
{
|
|
/**
|
|
* Persistent session
|
|
*
|
|
* @var \Magento\Persistent\Helper\Session
|
|
*/
|
|
protected $_persistentSession;
|
|
|
|
/**
|
|
* Customer repository
|
|
*
|
|
* @var \Magento\Customer\Api\CustomerRepositoryInterface
|
|
*/
|
|
protected $customerRepository;
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param \Magento\Persistent\Helper\Session $persistentSession
|
|
* @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
|
|
*/
|
|
public function __construct(
|
|
\Magento\Persistent\Helper\Session $persistentSession,
|
|
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
|
|
) {
|
|
$this->_persistentSession = $persistentSession;
|
|
$this->customerRepository = $customerRepository;
|
|
}
|
|
|
|
/**
|
|
* Update customer id and customer group id if user is in persistent session
|
|
*
|
|
* @param \Magento\Framework\Event\Observer $observer
|
|
* @return void
|
|
*/
|
|
public function execute(\Magento\Framework\Event\Observer $observer)
|
|
{
|
|
if (!$this->_persistentSession->isPersistent()) {
|
|
return;
|
|
}
|
|
|
|
$customerCookies = $observer->getEvent()->getCustomerCookies();
|
|
if ($customerCookies instanceof \Magento\Framework\DataObject) {
|
|
$persistentCustomer = $this->customerRepository->getById(
|
|
$this->_persistentSession->getSession()->getCustomerId()
|
|
);
|
|
$customerCookies->setCustomerId($persistentCustomer->getId());
|
|
$customerCookies->setCustomerGroupId($persistentCustomer->getGroupId());
|
|
}
|
|
}
|
|
}
|