Skip to content

Commit 6523e18

Browse files
committed
ACP2E-2025: Refix ACP2E-1445 for multiple store views in the frontend.
- Fixed the CR comments.
1 parent ecd472d commit 6523e18

File tree

9 files changed

+87
-107
lines changed

9 files changed

+87
-107
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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\Customer;
9+
10+
use Magento\Customer\Model\Context;
11+
use Magento\Framework\App\Http\Context as HttpContext;
12+
use Magento\Framework\View\Element\Block\ArgumentInterface;
13+
14+
/**
15+
* Customer's auth view model
16+
*/
17+
class Auth implements ArgumentInterface
18+
{
19+
/**
20+
* @param HttpContext $httpContext
21+
*/
22+
public function __construct(
23+
private HttpContext $httpContext
24+
) {}
25+
26+
/**
27+
* Check is user login
28+
*
29+
* @return bool
30+
*/
31+
public function isLoggedIn(): bool
32+
{
33+
return $this->httpContext->getValue(Context::CONTEXT_AUTH);
34+
}
35+
}

app/code/Magento/Customer/ViewModel/Customer/Data.php

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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\Customer;
9+
10+
use Magento\Framework\Serialize\Serializer\Json as Json;
11+
use Magento\Framework\View\Element\Block\ArgumentInterface;
12+
13+
/**
14+
* Customer's json serializer view model
15+
*/
16+
class JsonSerializer implements ArgumentInterface
17+
{
18+
/**
19+
* @param Json $jsonEncoder
20+
*/
21+
public function __construct(
22+
private Json $jsonEncoder
23+
) {}
24+
25+
/**
26+
* Encode the mixed $valueToEncode into the JSON format
27+
*
28+
* @param mixed $valueToEncode
29+
* @return string
30+
*/
31+
public function jsonEncode($valueToEncode): string
32+
{
33+
return $this->jsonEncoder->serialize($valueToEncode);
34+
}
35+
}

app/code/Magento/Customer/view/frontend/layout/default.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
<block name="customer.customer.data" class="Magento\Customer\Block\CustomerData"
5151
template="Magento_Customer::js/customer-data.phtml">
5252
<arguments>
53-
<argument name="view_model" xsi:type="object">Magento\Customer\ViewModel\Customer\Data</argument>
53+
<argument name="auth_view_model" xsi:type="object">Magento\Customer\ViewModel\Customer\Auth</argument>
54+
<argument name="json_serializer_view_model" xsi:type="object">Magento\Customer\ViewModel\Customer\JsonSerializer</argument>
5455
</arguments>
5556
</block>
5657
<block name="customer.data.invalidation.rules" class="Magento\Customer\Block\CustomerScopeData"

app/code/Magento/Customer/view/frontend/templates/js/customer-data.phtml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ use Magento\Framework\App\ObjectManager;
99
/** @var \Magento\Customer\Block\CustomerData $block */
1010

1111
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundHelper
12-
/** @var Data $viewModel */
13-
$viewModel = $block->getViewModel() ?? ObjectManager::getInstance()->get(Data::class);
12+
/** @var Auth $authViewModel */
13+
$authViewModel = $block->getAuthViewModel() ?? ObjectManager::getInstance()->get(Auth::class);
14+
/** @var JsonSerializer $jsonSerializerViewModel */
15+
$jsonSerializerViewModel = $block->getJsonSerializerViewModel() ?? ObjectManager::getInstance()->get(JsonSerializer::class);
1416
$customerDataUrl = $block->getCustomerDataUrl('customer/account/updateSession');
1517
$expirableSectionNames = $block->getExpirableSectionNames();
1618
?>
@@ -20,10 +22,10 @@ $expirableSectionNames = $block->getExpirableSectionNames();
2022
"Magento_Customer/js/customer-data": {
2123
"sectionLoadUrl": "<?= $block->escapeJs($block->getCustomerDataUrl('customer/section/load')) ?>",
2224
"expirableSectionLifetime": <?= (int)$block->getExpirableSectionLifetime() ?>,
23-
"expirableSectionNames": <?= /* @noEscape */ $viewModel->jsonEncode($expirableSectionNames) ?>,
25+
"expirableSectionNames": <?= /* @noEscape */ $jsonSerializerViewModel->jsonEncode($expirableSectionNames) ?>,
2426
"cookieLifeTime": "<?= $block->escapeJs($block->getCookieLifeTime()) ?>",
2527
"updateSessionUrl": "<?= $block->escapeJs($customerDataUrl) ?>",
26-
"isLoggedIn": "<?= /* @noEscape */ $viewModel->isLoggedIn() ?>"
28+
"isLoggedIn": "<?= /* @noEscape */ $authViewModel->isLoggedIn() ?>"
2729
}
2830
}
2931
}

app/code/Magento/PageCache/Model/App/Request/Http/IdentifierForSave.php

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace Magento\PageCache\Model\App\Request\Http;
99

1010
use Magento\Framework\App\Http\Context;
11-
use Magento\Framework\App\ObjectManager;
1211
use Magento\Framework\App\Request\Http;
1312
use Magento\Framework\Serialize\Serializer\Json;
1413
use Magento\Framework\App\PageCache\IdentifierInterface;
@@ -18,35 +17,16 @@
1817
*/
1918
class IdentifierForSave implements IdentifierInterface
2019
{
21-
/**
22-
* @var Http
23-
*/
24-
private $request;
25-
26-
/**
27-
* @var Context
28-
*/
29-
private $context;
30-
31-
/**
32-
* @var Json
33-
*/
34-
private $serializer;
35-
3620
/**
3721
* @param Http $request
3822
* @param Context $context
39-
* @param Json|null $serializer
23+
* @param Json $serializer
4024
*/
4125
public function __construct(
42-
Http $request,
43-
Context $context,
44-
Json $serializer = null
45-
) {
46-
$this->request = $request;
47-
$this->context = $context;
48-
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
49-
}
26+
private Http $request,
27+
private Context $context,
28+
private Json $serializer
29+
) {}
5030

5131
/**
5232
* Return unique page identifier

app/code/Magento/PageCache/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@
4747
<preference for="Magento\PageCache\Model\VclGeneratorInterface" type="Magento\PageCache\Model\Varnish\VclGenerator"/>
4848
<preference for="Magento\PageCache\Model\VclTemplateLocatorInterface" type="Magento\PageCache\Model\Varnish\VclTemplateLocator"/>
4949
<preference for="Magento\PageCache\Model\Spi\PageCacheTagsPreprocessorInterface" type="Magento\PageCache\Model\PageCacheTagsPreprocessorComposite"/>
50+
<preference for="Magento\Framework\App\PageCache\IdentifierInterface" type="Magento\Framework\App\PageCache\Identifier"/>
5051
</config>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
</type>
2929
<type name="Magento\Framework\App\PageCache\Kernel">
3030
<arguments>
31-
<argument name="identifierForSave" xsi:type="object">Magento\PageCache\Model\App\Request\Http\IdentifierForSave</argument>
31+
<argument name="identifier" xsi:type="object">Magento\PageCache\Model\App\Request\Http\IdentifierForSave</argument>
3232
</arguments>
3333
</type>
34-
<preference for="Magento\Framework\App\PageCache\IdentifierInterface" type="Magento\Framework\App\PageCache\Identifier"/>
3534
</config>

lib/internal/Magento/Framework/App/PageCache/Kernel.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ class Kernel
6363
*/
6464
private $state;
6565

66-
/**
67-
* @var \Magento\Framework\App\PageCache\IdentifierInterface
68-
*/
69-
private $identifierForSave;
70-
7166
/**
7267
* @param Cache $cache
7368
* @param \Magento\Framework\App\PageCache\IdentifierInterface $identifier
@@ -78,7 +73,6 @@ class Kernel
7873
* @param \Magento\Framework\Serialize\SerializerInterface|null $serializer
7974
* @param AppState|null $state
8075
* @param \Magento\PageCache\Model\Cache\Type|null $fullPageCache
81-
* @param \Magento\Framework\App\PageCache\IdentifierInterface $identifierForSave
8276
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8377
*/
8478
public function __construct(
@@ -90,8 +84,7 @@ public function __construct(
9084
\Magento\Framework\App\Response\HttpFactory $httpFactory = null,
9185
\Magento\Framework\Serialize\SerializerInterface $serializer = null,
9286
AppState $state = null,
93-
\Magento\PageCache\Model\Cache\Type $fullPageCache = null,
94-
\Magento\Framework\App\PageCache\IdentifierInterface $identifierForSave = null,
87+
\Magento\PageCache\Model\Cache\Type $fullPageCache = null
9588
) {
9689
$this->cache = $cache;
9790
$this->identifier = $identifier;
@@ -110,9 +103,6 @@ public function __construct(
110103
$this->fullPageCache = $fullPageCache ?? ObjectManager::getInstance()->get(
111104
\Magento\PageCache\Model\Cache\Type::class
112105
);
113-
$this->identifierForSave = $identifierForSave ?? ObjectManager::getInstance()->get(
114-
\Magento\Framework\App\PageCache\IdentifierInterface::class
115-
);
116106
}
117107

118108
/**
@@ -169,7 +159,7 @@ public function process(\Magento\Framework\App\Response\Http $response)
169159

170160
$this->fullPageCache->save(
171161
$this->serializer->serialize($this->getPreparedData($response)),
172-
$this->identifierForSave->getValue(),
162+
$this->identifier->getValue(),
173163
$tags,
174164
$maxAge
175165
);

0 commit comments

Comments
 (0)