File tree Expand file tree Collapse file tree 5 files changed +100
-0
lines changed
app/code/Magento/Customer Expand file tree Collapse file tree 5 files changed +100
-0
lines changed Original file line number Diff line number Diff line change
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 \Test \Unit \ViewModel ;
9
+
10
+ use PHPUnit \Framework \TestCase ;
11
+
12
+ class CookieSettings extends TestCase
13
+ {
14
+ /**
15
+ * @var \Magento\Customer\ViewModel\CookieSettings
16
+ */
17
+ private $ cookieSettings ;
18
+
19
+ /**
20
+ * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit\Framework\MockObject\MockObject
21
+ */
22
+ private $ scopeConfigMock ;
23
+
24
+ protected function setUp (): void
25
+ {
26
+ $ this ->scopeConfigMock = $ this ->getMockBuilder (\Magento \Framework \App \Config \ScopeConfigInterface::class)
27
+ ->getMockForAbstractClass ();
28
+
29
+ $ this ->cookieSettings = new \Magento \Customer \ViewModel \CookieSettings (
30
+ $ this ->scopeConfigMock
31
+ );
32
+ }
33
+
34
+ public function testGetCookieDomain ()
35
+ {
36
+ $ this ->scopeConfigMock ->expects ($ this ->once ())
37
+ ->method ('getValue ' )
38
+ ->with (
39
+ \Magento \Customer \ViewModel \CookieSettings::XML_PATH_COOKIE_DOMAIN ,
40
+ \Magento \Store \Model \ScopeInterface::SCOPE_STORE
41
+ )
42
+ ->willReturn ('example.com ' );
43
+
44
+ $ this ->assertEquals ('example.com ' , $ this ->cookieSettings ->getCookieDomain ());
45
+ }
46
+ }
Original file line number Diff line number Diff line change
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 \ViewModel ;
9
+
10
+ use Magento \Framework \View \Element \Block \ArgumentInterface ;
11
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
12
+
13
+ class CookieSettings implements ArgumentInterface
14
+ {
15
+ public const XML_PATH_COOKIE_DOMAIN = 'web/cookie/cookie_domain ' ;
16
+
17
+ /**
18
+ * @var ScopeConfigInterface
19
+ */
20
+ private $ scopeConfig ;
21
+
22
+ /**
23
+ * @param ScopeConfigInterface $scopeConfig
24
+ */
25
+ public function __construct (ScopeConfigInterface $ scopeConfig )
26
+ {
27
+ $ this ->scopeConfig = $ scopeConfig ;
28
+ }
29
+
30
+ /**
31
+ * Get cookie domain for a store view
32
+ *
33
+ * @return mixed
34
+ */
35
+ public function getCookieDomain ()
36
+ {
37
+ return $ this ->scopeConfig ->getValue (
38
+ self ::XML_PATH_COOKIE_DOMAIN ,
39
+ \Magento \Store \Model \ScopeInterface::SCOPE_STORE
40
+ );
41
+ }
42
+ }
Original file line number Diff line number Diff line change 52
52
<arguments >
53
53
<argument name =" auth" xsi : type =" object" >Magento\Customer\ViewModel\Customer\Auth</argument >
54
54
<argument name =" json_serializer" xsi : type =" object" >Magento\Customer\ViewModel\Customer\JsonSerializer</argument >
55
+ <argument name =" cookie_settings" xsi : type =" object" >Magento\Customer\ViewModel\CookieSettings</argument >
55
56
</arguments >
56
57
</block >
57
58
<block name =" customer.data.invalidation.rules" class =" Magento\Customer\Block\CustomerScopeData"
Original file line number Diff line number Diff line change 5
5
*/
6
6
use Magento \Customer \ViewModel \Customer \Data ;
7
7
use Magento \Framework \App \ObjectManager ;
8
+ use Magento \Customer \ViewModel \CookieSettings ;
8
9
9
10
/** @var \Magento\Customer\Block\CustomerData $block */
10
11
@@ -16,6 +17,8 @@ $jsonSerializer = $block->getJsonSerializer() ??
16
17
ObjectManager::getInstance ()->get (JsonSerializer::class);
17
18
$ customerDataUrl = $ block ->getCustomerDataUrl ('customer/account/updateSession ' );
18
19
$ expirableSectionNames = $ block ->getExpirableSectionNames ();
20
+ /** @var CookieSettings $cookieSettings */
21
+ $ cookieSettings = $ block ->getCookieSettings ();
19
22
?>
20
23
<script type="text/x-magento-init">
21
24
{
@@ -27,6 +30,7 @@ $expirableSectionNames = $block->getExpirableSectionNames();
27
30
$ expirableSectionNames
28
31
) ?> ,
29
32
"cookieLifeTime": "<?= $ block ->escapeJs ($ block ->getCookieLifeTime ()) ?> ",
33
+ "cookieDomain": "<?= $ block ->escapeJs ($ cookieSettings ->getCookieDomain ()) ?> ",
30
34
"updateSessionUrl": "<?= $ block ->escapeJs ($ customerDataUrl ) ?> ",
31
35
"isLoggedIn": "<?= /* @noEscape */ $ auth ->isLoggedIn () ?> "
32
36
}
Original file line number Diff line number Diff line change @@ -232,6 +232,13 @@ define([
232
232
path : '/' ,
233
233
expires : new Date ( Date . now ( ) + parseInt ( options . cookieLifeTime , 10 ) * 1000 )
234
234
} ) ;
235
+
236
+ if ( options . cookieDomain ) {
237
+ $ . cookieStorage . setConf ( {
238
+ domain : options . cookieDomain
239
+ } ) ;
240
+ }
241
+
235
242
storage = $ . initNamespaceStorage ( 'mage-cache-storage' ) . localStorage ;
236
243
storageInvalidation = $ . initNamespaceStorage ( 'mage-cache-storage-section-invalidation' ) . localStorage ;
237
244
} ,
You can’t perform that action at this time.
0 commit comments