|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Customer\Model\Cart; |
| 7 | + |
| 8 | +use Magento\Checkout\Block\Cart\Sidebar; |
| 9 | +use Magento\Framework\Exception\InputException; |
| 10 | +use Magento\Framework\Stdlib\Cookie\FailureToSendException; |
| 11 | +use Magento\Framework\Stdlib\Cookie\PhpCookieManager; |
| 12 | +use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory; |
| 13 | +use Magento\Framework\Session\SessionManagerInterface; |
| 14 | + |
| 15 | +class RemoveCookiesWhenQuoteIsNullPlugin |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @var PhpCookieManager |
| 19 | + */ |
| 20 | + private $cookieManager; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var CookieMetadataFactory |
| 24 | + */ |
| 25 | + private $cookieMetadataFactory; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var SessionManagerInterface |
| 29 | + */ |
| 30 | + private $sessionManager; |
| 31 | + |
| 32 | + /** |
| 33 | + * @param PhpCookieManager $cookieManager |
| 34 | + * @param CookieMetadataFactory $cookieMetadataFactory |
| 35 | + * @param SessionManagerInterface $sessionManager |
| 36 | + */ |
| 37 | + public function __construct( |
| 38 | + PhpCookieManager $cookieManager, |
| 39 | + CookieMetadataFactory $cookieMetadataFactory, |
| 40 | + SessionManagerInterface $sessionManager |
| 41 | + ) { |
| 42 | + $this->cookieManager = $cookieManager; |
| 43 | + $this->cookieMetadataFactory = $cookieMetadataFactory; |
| 44 | + $this->sessionManager = $sessionManager; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @param Sidebar $subject |
| 49 | + * @return void |
| 50 | + * @throws InputException |
| 51 | + * @throws FailureToSendException |
| 52 | + */ |
| 53 | + public function beforeGetConfig(Sidebar $subject) |
| 54 | + { |
| 55 | + if ($subject->getQuote()->getItems() === null) { |
| 56 | + $metadata = $this->cookieMetadataFactory->createCookieMetadata(); |
| 57 | + $metadata->setPath($this->sessionManager->getCookiePath()); |
| 58 | + $metadata->setDomain($this->sessionManager->getCookieDomain()); |
| 59 | + $this->cookieManager->deleteCookie('mage-cache-sessid', $metadata); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments