12
12
use Magento \Framework \App \RequestInterface ;
13
13
use Magento \Framework \App \Response \Http ;
14
14
use Magento \Framework \App \State ;
15
- use Magento \Framework \Stdlib \Cookie \CookieMetadataFactory ;
16
- use Magento \Framework \Stdlib \CookieManagerInterface ;
15
+ use Magento \Customer \Api \CustomerRepositoryInterface ;
17
16
18
17
class CustomerNotification
19
18
{
@@ -28,16 +27,9 @@ class CustomerNotification
28
27
private $ notificationStorage ;
29
28
30
29
/**
31
- * Cookie Manager
32
- *
33
- * @var \Magento\Framework\Stdlib\CookieManagerInterface
30
+ * @var CustomerRepositoryInterface
34
31
*/
35
- private $ cookieManager ;
36
-
37
- /**
38
- * @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory
39
- */
40
- private $ cookieMetadataFactory ;
32
+ private $ customerRepository ;
41
33
42
34
/**
43
35
* @var State
@@ -49,22 +41,18 @@ class CustomerNotification
49
41
*
50
42
* @param Session $session
51
43
* @param NotificationStorage $notificationStorage
52
- * @param CookieManagerInterface $cookieManager
53
- * @param CookieMetadataFactory $cookieMetadataFactory
54
44
* @param State $state
55
45
*/
56
46
public function __construct (
57
47
Session $ session ,
58
48
NotificationStorage $ notificationStorage ,
59
- CookieManagerInterface $ cookieManager ,
60
- CookieMetadataFactory $ cookieMetadataFactory ,
61
- State $ state
49
+ State $ state ,
50
+ CustomerRepositoryInterface $ customerRepository
62
51
) {
63
52
$ this ->session = $ session ;
64
53
$ this ->notificationStorage = $ notificationStorage ;
65
- $ this ->cookieManager = $ cookieManager ;
66
- $ this ->cookieMetadataFactory = $ cookieMetadataFactory ;
67
54
$ this ->state = $ state ;
55
+ $ this ->customerRepository = $ customerRepository ;
68
56
}
69
57
70
58
/**
@@ -75,24 +63,17 @@ public function __construct(
75
63
*/
76
64
public function beforeDispatch (AbstractAction $ subject , RequestInterface $ request )
77
65
{
78
- if ($ this ->state ->getAreaCode () == Area::AREA_FRONTEND
66
+ if ($ this ->state ->getAreaCode () == Area::AREA_FRONTEND && $ request -> isPost ()
79
67
&& $ this ->notificationStorage ->isExists (
80
68
NotificationStorage::UPDATE_CUSTOMER_SESSION ,
81
69
$ this ->session ->getCustomerId ()
82
70
)
83
71
) {
84
- $ publicCookieMetadata = $ this ->cookieMetadataFactory ->createPublicCookieMetadata ();
85
- $ publicCookieMetadata ->setDurationOneYear ();
86
- $ publicCookieMetadata ->setPath ('/ ' );
87
- $ publicCookieMetadata ->setHttpOnly (false );
88
- $ this ->cookieManager ->setPublicCookie (
89
- NotificationStorage::UPDATE_CUSTOMER_SESSION ,
90
- $ this ->session ->getCustomerId (),
91
- $ publicCookieMetadata
92
- );
93
-
94
- $ cookieMetadata = $ this ->cookieMetadataFactory ->createSensitiveCookieMetadata ()->setPath ('/ ' );
95
- $ this ->cookieManager ->deleteCookie (Http::COOKIE_VARY_STRING , $ cookieMetadata );
72
+ $ customer = $ this ->customerRepository ->getById ($ this ->session ->getCustomerId ());
73
+ $ this ->session ->setCustomerData ($ customer );
74
+ $ this ->session ->setCustomerGroupId ($ customer ->getGroupId ());
75
+ $ this ->session ->regenerateId ();
76
+ $ this ->notificationStorage ->remove (NotificationStorage::UPDATE_CUSTOMER_SESSION , $ customer ->getId ());
96
77
}
97
78
}
98
79
}
0 commit comments