DepersonalizePlugin.php 1.3 KB

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