Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DepersonalizePlugin.php
Go to the documentation of this file.
1 <?php
9 
11 
16 {
21 
25  protected $session;
26 
30  protected $customerSession;
31 
35  protected $customerFactory;
36 
40  protected $visitor;
41 
45  protected $customerGroupId;
46 
50  protected $formKey;
51 
59  public function __construct(
63  \Magento\Customer\Model\CustomerFactory $customerFactory,
65  ) {
66  $this->session = $session;
67  $this->customerSession = $customerSession;
68  $this->customerFactory = $customerFactory;
69  $this->visitor = $visitor;
70  $this->depersonalizeChecker = $depersonalizeChecker;
71  }
72 
79  public function beforeGenerateXml(\Magento\Framework\View\LayoutInterface $subject)
80  {
81  if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
82  $this->customerGroupId = $this->customerSession->getCustomerGroupId();
83  $this->formKey = $this->session->getData(\Magento\Framework\Data\Form\FormKey::FORM_KEY);
84  }
85  return [];
86  }
87 
95  public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
96  {
97  if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
98  $this->visitor->setSkipRequestLogging(true);
99  $this->visitor->unsetData();
100  $this->session->clearStorage();
101  $this->customerSession->clearStorage();
102  $this->session->setData(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $this->formKey);
103  $this->customerSession->setCustomerGroupId($this->customerGroupId);
104  $this->customerSession->setCustomer($this->customerFactory->create()->setGroupId($this->customerGroupId));
105  }
106  return $result;
107  }
108 }
afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
beforeGenerateXml(\Magento\Framework\View\LayoutInterface $subject)
__construct(DepersonalizeChecker $depersonalizeChecker, \Magento\Framework\Session\SessionManagerInterface $session, \Magento\Customer\Model\Session $customerSession, \Magento\Customer\Model\CustomerFactory $customerFactory, \Magento\Customer\Model\Visitor $visitor)