Skip to content

Commit 7377726

Browse files
committed
ACP2E-1445: Customer data in Local Storage not reset when session file lost
- Fixed the issue.
1 parent d48a739 commit 7377726

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
}

app/code/Magento/Customer/etc/frontend/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
<type name="Magento\Checkout\Block\Cart\Sidebar">
5858
<plugin name="customer_cart" type="Magento\Customer\Model\Cart\ConfigPlugin" />
5959
</type>
60+
<type name="Magento\Checkout\Block\Cart\Sidebar">
61+
<plugin name="customer_remove_items_from_cart" type="Magento\Customer\Model\Cart\RemoveCookiesWhenQuoteIsNullPlugin" />
62+
</type>
6063
<type name="Magento\Framework\Session\SessionManagerInterface">
6164
<plugin name="session_checker" type="Magento\Customer\CustomerData\Plugin\SessionChecker" />
6265
</type>

0 commit comments

Comments
 (0)