Skip to content

Commit 30e0bbb

Browse files
committed
MC-18719: private cookie version increments each post request
1 parent 4be0ec0 commit 30e0bbb

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Magento\Customer\Block;
4+
5+
use Magento\Customer\CustomerData\SectionPoolInterface;
6+
use Magento\Framework\View\Element\Block\ArgumentInterface;
7+
8+
/**
9+
* ViewModel to get sections names array.
10+
*/
11+
class SectionsNameProvider implements ArgumentInterface
12+
{
13+
/**
14+
* @var SectionPoolInterface
15+
*/
16+
private $sectionPool;
17+
18+
/**
19+
* @param SectionPoolInterface $sectionPool
20+
*/
21+
public function __construct(
22+
SectionPoolInterface $sectionPool
23+
) {
24+
$this->sectionPool = $sectionPool;
25+
}
26+
27+
/**
28+
* Return array of section names.
29+
*
30+
* @return array
31+
*/
32+
public function getSectionsName()
33+
{
34+
return array_keys($this->sectionPool->getSectionsData());
35+
}
36+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@
4444
template="Magento_Customer::js/section-config.phtml"/>
4545
<block name="customer.customer.data"
4646
class="Magento\Customer\Block\CustomerData"
47-
template="Magento_Customer::js/customer-data.phtml"/>
47+
template="Magento_Customer::js/customer-data.phtml">
48+
<arguments>
49+
<argument name="sectionsNameProvider" xsi:type="object">Magento\Customer\Block\SectionsNameProvider</argument>
50+
</arguments>
51+
</block>
4852
<block name="customer.data.invalidation.rules" class="Magento\Customer\Block\CustomerScopeData"
4953
template="Magento_Customer::js/customer-data/invalidation-rules.phtml"/>
5054
</referenceContainer>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"expirableSectionLifetime": <?= (int)$block->getExpirableSectionLifetime() ?>,
1515
"expirableSectionNames": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($block->getExpirableSectionNames()) ?>,
1616
"cookieLifeTime": "<?= $block->escapeJs($block->getCookieLifeTime()) ?>",
17-
"updateSessionUrl": "<?= $block->escapeJs($block->escapeUrl($block->getCustomerDataUrl('customer/account/updateSession'))) ?>"
17+
"updateSessionUrl": "<?= $block->escapeJs($block->escapeUrl($block->getCustomerDataUrl('customer/account/updateSession'))) ?>",
18+
"sectionsName": <?= $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($block->getData('sectionsNameProvider')->getSectionsName()) ?>
1819
}
1920
}
2021
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ define([
320320
var sectionDataIds,
321321
sectionsNamesForInvalidation;
322322

323-
sectionsNamesForInvalidation = _.contains(sectionNames, '*') ? buffer.keys() : sectionNames;
323+
sectionsNamesForInvalidation = _.contains(sectionNames, '*') ? options.sectionsName : sectionNames;
324324
$(document).trigger('customer-data-invalidate', [sectionsNamesForInvalidation]);
325325
buffer.remove(sectionsNamesForInvalidation);
326326
sectionDataIds = $.cookieStorage.get('section_data_ids') || {};

0 commit comments

Comments
 (0)