123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- /**
- * Depersonalize customer session data
- *
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Customer\Model\Layout;
- use Magento\PageCache\Model\DepersonalizeChecker;
- /**
- * Class DepersonalizePlugin
- */
- class DepersonalizePlugin
- {
- /**
- * @var DepersonalizeChecker
- */
- protected $depersonalizeChecker;
- /**
- * @var \Magento\Framework\Session\SessionManagerInterface
- */
- protected $session;
- /**
- * @var \Magento\Customer\Model\Session
- */
- protected $customerSession;
- /**
- * @var \Magento\Customer\Model\CustomerFactory
- */
- protected $customerFactory;
- /**
- * @var \Magento\Customer\Model\Visitor
- */
- protected $visitor;
- /**
- * @var int
- */
- protected $customerGroupId;
- /**
- * @var string
- */
- protected $formKey;
- /**
- * @param DepersonalizeChecker $depersonalizeChecker
- * @param \Magento\Framework\Session\SessionManagerInterface $session
- * @param \Magento\Customer\Model\Session $customerSession
- * @param \Magento\Customer\Model\CustomerFactory $customerFactory
- * @param \Magento\Customer\Model\Visitor $visitor
- */
- public function __construct(
- DepersonalizeChecker $depersonalizeChecker,
- \Magento\Framework\Session\SessionManagerInterface $session,
- \Magento\Customer\Model\Session $customerSession,
- \Magento\Customer\Model\CustomerFactory $customerFactory,
- \Magento\Customer\Model\Visitor $visitor
- ) {
- $this->session = $session;
- $this->customerSession = $customerSession;
- $this->customerFactory = $customerFactory;
- $this->visitor = $visitor;
- $this->depersonalizeChecker = $depersonalizeChecker;
- }
- /**
- * Before generate Xml
- *
- * @param \Magento\Framework\View\LayoutInterface $subject
- * @return array
- */
- public function beforeGenerateXml(\Magento\Framework\View\LayoutInterface $subject)
- {
- if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
- $this->customerGroupId = $this->customerSession->getCustomerGroupId();
- $this->formKey = $this->session->getData(\Magento\Framework\Data\Form\FormKey::FORM_KEY);
- }
- return [];
- }
- /**
- * After generate Xml
- *
- * @param \Magento\Framework\View\LayoutInterface $subject
- * @param \Magento\Framework\View\LayoutInterface $result
- * @return \Magento\Framework\View\LayoutInterface
- */
- public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
- {
- if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
- $this->visitor->setSkipRequestLogging(true);
- $this->visitor->unsetData();
- $this->session->clearStorage();
- $this->customerSession->clearStorage();
- $this->session->setData(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $this->formKey);
- $this->customerSession->setCustomerGroupId($this->customerGroupId);
- $this->customerSession->setCustomer($this->customerFactory->create()->setGroupId($this->customerGroupId));
- }
- return $result;
- }
- }
|