Skip to content

Commit f6583ee

Browse files
Merge branch '2.4-develop' into stability_control
2 parents 45b638e + 1bdf9df commit f6583ee

File tree

28 files changed

+1015
-104
lines changed

28 files changed

+1015
-104
lines changed

app/code/Magento/Bundle/Test/Mftf/Data/ProductData.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
<data key="fixedPriceFormatted">$10.00</data>
3232
<data key="defaultAttribute">Default</data>
3333
</entity>
34+
<entity name="BundleProductWithSlashSku" type="product">
35+
<data key="name">BundleProduct</data>
36+
<data key="sku">bu/ndle</data>
37+
<data key="status">1</data>
38+
</entity>
3439
<entity name="FixedBundleProduct" type="product2">
3540
<data key="name" unique="suffix">FixedBundleProduct</data>
3641
<data key="sku" unique="suffix">fixed-bundle-product</data>

app/code/Magento/CatalogInventory/Model/Quote/Item/QuantityValidator/QuoteItemQtyList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class QuoteItemQtyList
3333
public function getQty($productId, $quoteItemId, $quoteId, $itemQty)
3434
{
3535
$qty = $itemQty;
36-
if (isset($this->_checkedQuoteItems[$quoteId][$productId]['qty']) && !in_array(
36+
if (isset($this->_checkedQuoteItems[$quoteId][$productId]['qty']) && $quoteItemId !== null && !in_array(
3737
$quoteItemId,
3838
$this->_checkedQuoteItems[$quoteId][$productId]['items']
3939
)

app/code/Magento/CatalogInventory/Test/Unit/Model/Quote/Item/QuantityValidator/QuoteItemQtyListTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public function testSingleQuoteItemQty()
4949

5050
$qty = $this->quoteItemQtyList->getQty(125, 1, 11232, 1);
5151
$this->assertEquals($this->itemQtyTestValue, $qty);
52+
53+
$this->itemQtyTestValue = 2;
54+
$qty = $this->quoteItemQtyList->getQty(125, null, 11232, 1);
55+
$this->assertNotEquals($this->itemQtyTestValue, $qty);
5256
}
5357

5458
/**
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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\Customer;
9+
10+
use Magento\Customer\ViewModel\Customer\Auth;
11+
use Magento\Framework\App\Http\Context;
12+
use PHPUnit\Framework\MockObject\MockObject;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class AuthTest extends TestCase
16+
{
17+
/**
18+
* @var Context|MockObject
19+
*/
20+
private mixed $contextMock;
21+
22+
/**
23+
* @var Auth
24+
*/
25+
private Auth $model;
26+
27+
/**
28+
* @inheritdoc
29+
*/
30+
protected function setUp(): void
31+
{
32+
$this->contextMock = $this->getMockBuilder(Context::class)
33+
->disableOriginalConstructor()
34+
->getMock();
35+
36+
$this->model = new Auth(
37+
$this->contextMock
38+
);
39+
parent::setUp();
40+
}
41+
42+
/**
43+
* Test is logged in value.
44+
*
45+
* @return void
46+
*/
47+
public function testIsLoggedIn(): void
48+
{
49+
$this->contextMock->expects($this->once())
50+
->method('getValue')
51+
->willReturn(true);
52+
53+
$this->assertEquals(
54+
true,
55+
$this->model->isLoggedIn()
56+
);
57+
}
58+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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\Customer;
9+
10+
use Magento\Customer\ViewModel\Customer\JsonSerializer;
11+
use Magento\Framework\Serialize\Serializer\Json as Json;
12+
use PHPUnit\Framework\MockObject\MockObject;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class JsonSerializerTest extends TestCase
16+
{
17+
/**
18+
* @var Json|MockObject
19+
*/
20+
private mixed $jsonEncoderMock;
21+
22+
/**
23+
* @var JsonSerializer
24+
*/
25+
private JsonSerializer $model;
26+
27+
/**
28+
* @inheritdoc
29+
*/
30+
protected function setUp(): void
31+
{
32+
$this->jsonEncoderMock = $this->getMockBuilder(Json::class)
33+
->disableOriginalConstructor()
34+
->getMock();
35+
36+
$this->model = new JsonSerializer(
37+
$this->jsonEncoderMock
38+
);
39+
parent::setUp();
40+
}
41+
42+
/**
43+
* Test serialize value.
44+
*
45+
* @return void
46+
*/
47+
public function testSerialize(): void
48+
{
49+
$this->jsonEncoderMock->expects($this->once())
50+
->method('serialize')
51+
->willReturnCallback(
52+
function ($value) {
53+
return json_encode($value);
54+
}
55+
);
56+
57+
$this->assertEquals(
58+
json_encode(
59+
[
60+
'http://example.com/customer/section/load/'
61+
]
62+
),
63+
$this->model->serialize(['http://example.com/customer/section/load/'])
64+
);
65+
}
66+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
/**
28+
* Check is user login
29+
*
30+
* @return bool
31+
*/
32+
public function isLoggedIn(): bool
33+
{
34+
return $this->httpContext->getValue(Context::CONTEXT_AUTH) ?? false;
35+
}
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
/**
27+
* Encode the mixed $value into the JSON format
28+
*
29+
* @param mixed $value
30+
* @return string
31+
*/
32+
public function serialize(mixed $value): string
33+
{
34+
return $this->jsonEncoder->serialize($value);
35+
}
36+
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@
4848
</arguments>
4949
</block>
5050
<block name="customer.customer.data" class="Magento\Customer\Block\CustomerData"
51-
template="Magento_Customer::js/customer-data.phtml"/>
51+
template="Magento_Customer::js/customer-data.phtml">
52+
<arguments>
53+
<argument name="auth" xsi:type="object">Magento\Customer\ViewModel\Customer\Auth</argument>
54+
<argument name="json_serializer" xsi:type="object">Magento\Customer\ViewModel\Customer\JsonSerializer</argument>
55+
</arguments>
56+
</block>
5257
<block name="customer.data.invalidation.rules" class="Magento\Customer\Block\CustomerScopeData"
5358
template="Magento_Customer::js/customer-data/invalidation-rules.phtml"/>
5459
</referenceContainer>

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,32 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
use Magento\Customer\ViewModel\Customer\Data;
7+
use Magento\Framework\App\ObjectManager;
68

79
/** @var \Magento\Customer\Block\CustomerData $block */
8-
/** @var \Magento\Framework\Json\Helper\Data $jsonHelper */
9-
$expirableSectionNames = $block->getExpirableSectionNames();
1010

1111
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundHelper
12-
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
13-
$jsonHelper = $this->helper(\Magento\Framework\Json\Helper\Data::class);
12+
/** @var Auth $auth */
13+
$auth = $block->getAuth() ?? ObjectManager::getInstance()->get(Auth::class);
14+
/** @var JsonSerializer $jsonSerializer */
15+
$jsonSerializer = $block->getJsonSerializer() ??
16+
ObjectManager::getInstance()->get(JsonSerializer::class);
17+
$customerDataUrl = $block->getCustomerDataUrl('customer/account/updateSession');
18+
$expirableSectionNames = $block->getExpirableSectionNames();
1419
?>
1520
<script type="text/x-magento-init">
1621
{
1722
"*": {
1823
"Magento_Customer/js/customer-data": {
1924
"sectionLoadUrl": "<?= $block->escapeJs($block->getCustomerDataUrl('customer/section/load')) ?>",
2025
"expirableSectionLifetime": <?= (int)$block->getExpirableSectionLifetime() ?>,
21-
"expirableSectionNames": <?= /* @noEscape */ $jsonHelper->jsonEncode(
22-
$block->getExpirableSectionNames()
26+
"expirableSectionNames": <?= /* @noEscape */ $jsonSerializer->serialize(
27+
$expirableSectionNames
2328
) ?>,
2429
"cookieLifeTime": "<?= $block->escapeJs($block->getCookieLifeTime()) ?>",
25-
"updateSessionUrl": "<?= $block->escapeJs(
26-
$block->getCustomerDataUrl('customer/account/updateSession')
27-
) ?>"
30+
"updateSessionUrl": "<?= $block->escapeJs($customerDataUrl) ?>",
31+
"isLoggedIn": "<?= /* @noEscape */ $auth->isLoggedIn() ?>"
2832
}
2933
}
3034
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,20 @@ define([
4747
* Invalidate Cache By Close Cookie Session
4848
*/
4949
invalidateCacheByCloseCookieSession = function () {
50+
var isLoggedIn = parseInt(options.isLoggedIn, 10) || 0;
51+
5052
if (!$.cookieStorage.isSet('mage-cache-sessid')) {
5153
storage.removeAll();
5254
}
5355

56+
if (!$.localStorage.isSet('mage-customer-login')) {
57+
$.localStorage.set('mage-customer-login', isLoggedIn);
58+
}
59+
if ($.localStorage.get('mage-customer-login') !== isLoggedIn) {
60+
$.localStorage.set('mage-customer-login', isLoggedIn);
61+
storage.removeAll();
62+
}
63+
5464
$.cookieStorage.set('mage-cache-sessid', true);
5565
};
5666

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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\PageCache\Model\App\Request\Http;
9+
10+
use Magento\Framework\App\Http\Context;
11+
use Magento\Framework\App\Request\Http;
12+
use Magento\Framework\Serialize\Serializer\Json;
13+
use Magento\Framework\App\PageCache\IdentifierInterface;
14+
15+
/**
16+
* Page unique identifier
17+
*/
18+
class IdentifierForSave implements IdentifierInterface
19+
{
20+
/**
21+
* @param Http $request
22+
* @param Context $context
23+
* @param Json $serializer
24+
*/
25+
public function __construct(
26+
private Http $request,
27+
private Context $context,
28+
private Json $serializer
29+
) {
30+
}
31+
32+
/**
33+
* Return unique page identifier
34+
*
35+
* @return string
36+
*/
37+
public function getValue()
38+
{
39+
$data = [
40+
$this->request->isSecure(),
41+
$this->request->getUriString(),
42+
$this->context->getVaryString()
43+
];
44+
45+
return sha1($this->serializer->serialize($data));
46+
}
47+
}

0 commit comments

Comments
 (0)