DepersonalizePlugin.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Depersonalize catalog session data
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Catalog\Model\Layout;
  9. use Magento\PageCache\Model\DepersonalizeChecker;
  10. /**
  11. * Class DepersonalizePlugin
  12. */
  13. class DepersonalizePlugin
  14. {
  15. /**
  16. * @var DepersonalizeChecker
  17. */
  18. protected $depersonalizeChecker;
  19. /**
  20. * Catalog session
  21. *
  22. * @var \Magento\Catalog\Model\Session
  23. */
  24. protected $catalogSession;
  25. /**
  26. * @param DepersonalizeChecker $depersonalizeChecker
  27. * @param \Magento\Catalog\Model\Session $catalogSession
  28. */
  29. public function __construct(
  30. DepersonalizeChecker $depersonalizeChecker,
  31. \Magento\Catalog\Model\Session $catalogSession
  32. ) {
  33. $this->catalogSession = $catalogSession;
  34. $this->depersonalizeChecker = $depersonalizeChecker;
  35. }
  36. /**
  37. * After generate Xml
  38. *
  39. * @param \Magento\Framework\View\LayoutInterface $subject
  40. * @param \Magento\Framework\View\LayoutInterface $result
  41. * @return \Magento\Framework\View\LayoutInterface
  42. */
  43. public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
  44. {
  45. if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
  46. $this->catalogSession->clearStorage();
  47. }
  48. return $result;
  49. }
  50. }