Skip to content

Commit

Permalink
Merge pull request #8341 from magento-l3/JUN062023_PR_sarmistha
Browse files Browse the repository at this point in the history
[L3 Kings] Bugfix delivery
  • Loading branch information
2 parents 528cfb0 + 5766328 commit 1bdf9df
Show file tree
Hide file tree
Showing 28 changed files with 1,015 additions and 104 deletions.
5 changes: 5 additions & 0 deletions app/code/Magento/Bundle/Test/Mftf/Data/ProductData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<data key="fixedPriceFormatted">$10.00</data>
<data key="defaultAttribute">Default</data>
</entity>
<entity name="BundleProductWithSlashSku" type="product">
<data key="name">BundleProduct</data>
<data key="sku">bu/ndle</data>
<data key="status">1</data>
</entity>
<entity name="FixedBundleProduct" type="product2">
<data key="name" unique="suffix">FixedBundleProduct</data>
<data key="sku" unique="suffix">fixed-bundle-product</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class QuoteItemQtyList
public function getQty($productId, $quoteItemId, $quoteId, $itemQty)
{
$qty = $itemQty;
if (isset($this->_checkedQuoteItems[$quoteId][$productId]['qty']) && !in_array(
if (isset($this->_checkedQuoteItems[$quoteId][$productId]['qty']) && $quoteItemId !== null && !in_array(
$quoteItemId,
$this->_checkedQuoteItems[$quoteId][$productId]['items']
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public function testSingleQuoteItemQty()

$qty = $this->quoteItemQtyList->getQty(125, 1, 11232, 1);
$this->assertEquals($this->itemQtyTestValue, $qty);

$this->itemQtyTestValue = 2;
$qty = $this->quoteItemQtyList->getQty(125, null, 11232, 1);
$this->assertNotEquals($this->itemQtyTestValue, $qty);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Customer\Test\Unit\ViewModel\Customer;

use Magento\Customer\ViewModel\Customer\Auth;
use Magento\Framework\App\Http\Context;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class AuthTest extends TestCase
{
/**
* @var Context|MockObject
*/
private mixed $contextMock;

/**
* @var Auth
*/
private Auth $model;

/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->contextMock = $this->getMockBuilder(Context::class)
->disableOriginalConstructor()
->getMock();

$this->model = new Auth(
$this->contextMock
);
parent::setUp();
}

/**
* Test is logged in value.
*
* @return void
*/
public function testIsLoggedIn(): void
{
$this->contextMock->expects($this->once())
->method('getValue')
->willReturn(true);

$this->assertEquals(
true,
$this->model->isLoggedIn()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Customer\Test\Unit\ViewModel\Customer;

use Magento\Customer\ViewModel\Customer\JsonSerializer;
use Magento\Framework\Serialize\Serializer\Json as Json;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class JsonSerializerTest extends TestCase
{
/**
* @var Json|MockObject
*/
private mixed $jsonEncoderMock;

/**
* @var JsonSerializer
*/
private JsonSerializer $model;

/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->jsonEncoderMock = $this->getMockBuilder(Json::class)
->disableOriginalConstructor()
->getMock();

$this->model = new JsonSerializer(
$this->jsonEncoderMock
);
parent::setUp();
}

/**
* Test serialize value.
*
* @return void
*/
public function testSerialize(): void
{
$this->jsonEncoderMock->expects($this->once())
->method('serialize')
->willReturnCallback(
function ($value) {
return json_encode($value);
}
);

$this->assertEquals(
json_encode(
[
'http://example.com/customer/section/load/'
]
),
$this->model->serialize(['http://example.com/customer/section/load/'])
);
}
}
36 changes: 36 additions & 0 deletions app/code/Magento/Customer/ViewModel/Customer/Auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Customer\ViewModel\Customer;

use Magento\Customer\Model\Context;
use Magento\Framework\App\Http\Context as HttpContext;
use Magento\Framework\View\Element\Block\ArgumentInterface;

/**
* Customer's auth view model
*/
class Auth implements ArgumentInterface
{
/**
* @param HttpContext $httpContext
*/
public function __construct(
private HttpContext $httpContext
) {
}

/**
* Check is user login
*
* @return bool
*/
public function isLoggedIn(): bool
{
return $this->httpContext->getValue(Context::CONTEXT_AUTH) ?? false;
}
}
36 changes: 36 additions & 0 deletions app/code/Magento/Customer/ViewModel/Customer/JsonSerializer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Customer\ViewModel\Customer;

use Magento\Framework\Serialize\Serializer\Json as Json;
use Magento\Framework\View\Element\Block\ArgumentInterface;

/**
* Customer's json serializer view model
*/
class JsonSerializer implements ArgumentInterface
{
/**
* @param Json $jsonEncoder
*/
public function __construct(
private Json $jsonEncoder
) {
}

/**
* Encode the mixed $value into the JSON format
*
* @param mixed $value
* @return string
*/
public function serialize(mixed $value): string
{
return $this->jsonEncoder->serialize($value);
}
}
7 changes: 6 additions & 1 deletion app/code/Magento/Customer/view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@
</arguments>
</block>
<block name="customer.customer.data" class="Magento\Customer\Block\CustomerData"
template="Magento_Customer::js/customer-data.phtml"/>
template="Magento_Customer::js/customer-data.phtml">
<arguments>
<argument name="auth" xsi:type="object">Magento\Customer\ViewModel\Customer\Auth</argument>
<argument name="json_serializer" xsi:type="object">Magento\Customer\ViewModel\Customer\JsonSerializer</argument>
</arguments>
</block>
<block name="customer.data.invalidation.rules" class="Magento\Customer\Block\CustomerScopeData"
template="Magento_Customer::js/customer-data/invalidation-rules.phtml"/>
</referenceContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,32 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Customer\ViewModel\Customer\Data;
use Magento\Framework\App\ObjectManager;

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

// phpcs:disable Magento2.Templates.ThisInTemplate.FoundHelper
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
$jsonHelper = $this->helper(\Magento\Framework\Json\Helper\Data::class);
/** @var Auth $auth */
$auth = $block->getAuth() ?? ObjectManager::getInstance()->get(Auth::class);
/** @var JsonSerializer $jsonSerializer */
$jsonSerializer = $block->getJsonSerializer() ??
ObjectManager::getInstance()->get(JsonSerializer::class);
$customerDataUrl = $block->getCustomerDataUrl('customer/account/updateSession');
$expirableSectionNames = $block->getExpirableSectionNames();
?>
<script type="text/x-magento-init">
{
"*": {
"Magento_Customer/js/customer-data": {
"sectionLoadUrl": "<?= $block->escapeJs($block->getCustomerDataUrl('customer/section/load')) ?>",
"expirableSectionLifetime": <?= (int)$block->getExpirableSectionLifetime() ?>,
"expirableSectionNames": <?= /* @noEscape */ $jsonHelper->jsonEncode(
$block->getExpirableSectionNames()
"expirableSectionNames": <?= /* @noEscape */ $jsonSerializer->serialize(
$expirableSectionNames
) ?>,
"cookieLifeTime": "<?= $block->escapeJs($block->getCookieLifeTime()) ?>",
"updateSessionUrl": "<?= $block->escapeJs(
$block->getCustomerDataUrl('customer/account/updateSession')
) ?>"
"updateSessionUrl": "<?= $block->escapeJs($customerDataUrl) ?>",
"isLoggedIn": "<?= /* @noEscape */ $auth->isLoggedIn() ?>"
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions app/code/Magento/Customer/view/frontend/web/js/customer-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,20 @@ define([
* Invalidate Cache By Close Cookie Session
*/
invalidateCacheByCloseCookieSession = function () {
var isLoggedIn = parseInt(options.isLoggedIn, 10) || 0;

if (!$.cookieStorage.isSet('mage-cache-sessid')) {
storage.removeAll();
}

if (!$.localStorage.isSet('mage-customer-login')) {
$.localStorage.set('mage-customer-login', isLoggedIn);
}
if ($.localStorage.get('mage-customer-login') !== isLoggedIn) {
$.localStorage.set('mage-customer-login', isLoggedIn);
storage.removeAll();
}

$.cookieStorage.set('mage-cache-sessid', true);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\PageCache\Model\App\Request\Http;

use Magento\Framework\App\Http\Context;
use Magento\Framework\App\Request\Http;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\App\PageCache\IdentifierInterface;

/**
* Page unique identifier
*/
class IdentifierForSave implements IdentifierInterface
{
/**
* @param Http $request
* @param Context $context
* @param Json $serializer
*/
public function __construct(
private Http $request,
private Context $context,
private Json $serializer
) {
}

/**
* Return unique page identifier
*
* @return string
*/
public function getValue()
{
$data = [
$this->request->isSecure(),
$this->request->getUriString(),
$this->context->getVaryString()
];

return sha1($this->serializer->serialize($data));
}
}
Loading

0 comments on commit 1bdf9df

Please sign in to comment.