Skip to content

Commit 3142715

Browse files
committed
ACP2E-1445: Customer data in Local Storage not reset when session file lost
- Implemented the new solution approach.
1 parent 79e075c commit 3142715

File tree

3 files changed

+59
-21
lines changed

3 files changed

+59
-21
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Model\App\FrontController;
9+
10+
use Magento\Framework\App\Response\Http as ResponseHttp;
11+
use Magento\Customer\Model\Session;
12+
13+
/**
14+
* Plugin for delete the cookie when the customer is not exist.
15+
*
16+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
17+
*/
18+
class DeleteCookieWhenCustomerNotExistPlugin
19+
{
20+
/**
21+
* @var ResponseHttp
22+
*/
23+
private $responseHttp;
24+
25+
/**
26+
* @var Session
27+
*/
28+
private $session;
29+
30+
/**
31+
* Constructor
32+
*
33+
* @param ResponseHttp $responseHttp
34+
* @param Session $session
35+
*/
36+
public function __construct(
37+
ResponseHttp $responseHttp,
38+
Session $session
39+
) {
40+
$this->responseHttp = $responseHttp;
41+
$this->session = $session;
42+
}
43+
44+
/**
45+
* Delete the cookie when the customer is not exist before dispatch the front controller.
46+
*
47+
* @return void
48+
*/
49+
public function beforeDispatch(): void
50+
{
51+
if (!$this->session->getCustomerId()) {
52+
$this->responseHttp->sendVary();
53+
}
54+
}
55+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,7 @@
127127
</argument>
128128
</arguments>
129129
</type>
130+
<type name="Magento\Framework\App\FrontControllerInterface">
131+
<plugin name="delete-cookie-when-customer-not-exist" type="Magento\Customer\Model\App\FrontController\DeleteCookieWhenCustomerNotExistPlugin"/>
132+
</type>
130133
</config>

app/code/Magento/PageCache/Model/App/FrontController/BuiltinPlugin.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\PageCache\Model\App\FrontController;
77

88
use Magento\Framework\App\Response\Http as ResponseHttp;
9-
use Magento\Customer\Model\Session;
109

1110
/**
1211
* Plugin for processing builtin cache
@@ -33,40 +32,24 @@ class BuiltinPlugin
3332
*/
3433
protected $state;
3534

36-
/**
37-
* @var ResponseHttp
38-
*/
39-
protected $responseHttp;
40-
41-
/**
42-
* @var Session
43-
*/
44-
private $session;
45-
4635
/**
4736
* Constructor
4837
*
4938
* @param \Magento\PageCache\Model\Config $config
5039
* @param \Magento\Framework\App\PageCache\Version $version
5140
* @param \Magento\Framework\App\PageCache\Kernel $kernel
5241
* @param \Magento\Framework\App\State $state
53-
* @param ResponseHttp $responseHttp
54-
* @param Session $session
5542
*/
5643
public function __construct(
5744
\Magento\PageCache\Model\Config $config,
5845
\Magento\Framework\App\PageCache\Version $version,
5946
\Magento\Framework\App\PageCache\Kernel $kernel,
60-
\Magento\Framework\App\State $state,
61-
ResponseHttp $responseHttp,
62-
Session $session
47+
\Magento\Framework\App\State $state
6348
) {
6449
$this->config = $config;
6550
$this->version = $version;
6651
$this->kernel = $kernel;
6752
$this->state = $state;
68-
$this->responseHttp = $responseHttp;
69-
$this->session = $session;
7053
}
7154

7255
/**
@@ -83,9 +66,6 @@ public function aroundDispatch(
8366
\Closure $proceed,
8467
\Magento\Framework\App\RequestInterface $request
8568
) {
86-
if (!$this->session->getCustomerId()) {
87-
$this->responseHttp->sendVary();
88-
}
8969
$this->version->process();
9070
if (!$this->config->isEnabled() || $this->config->getType() !== \Magento\PageCache\Model\Config::BUILT_IN) {
9171
return $proceed($request);

0 commit comments

Comments
 (0)