File tree Expand file tree Collapse file tree 3 files changed +31
-5
lines changed
app/code/Magento/PageCache Expand file tree Collapse file tree 3 files changed +31
-5
lines changed Original file line number Diff line number Diff line change 7
7
8
8
namespace Magento \PageCache \ViewModel ;
9
9
10
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
10
11
use Magento \Framework \View \Element \Block \ArgumentInterface ;
11
12
use Magento \PageCache \Model \Config ;
12
13
15
16
*/
16
17
class FormKeyProvider implements ArgumentInterface
17
18
{
19
+ /**
20
+ * XML PATH to enable/disable saving toolbar parameters to session
21
+ */
22
+ const XML_PATH_CATALOG_REMEMBER_PAGINATION = 'catalog/frontend/remember_pagination ' ;
23
+
18
24
/**
19
25
* @var Config
20
26
*/
21
- private $ config ;
27
+ private Config $ config ;
28
+
29
+ /**
30
+ * @var ScopeConfigInterface object
31
+ */
32
+ private ScopeConfigInterface $ scopeConfig ;
22
33
23
34
/**
24
35
* @param Config $config
36
+ * @param ScopeConfigInterface $scopeConfig
25
37
*/
26
38
public function __construct (
27
- Config $ config
39
+ Config $ config ,
40
+ ScopeConfigInterface $ scopeConfig
28
41
) {
29
42
$ this ->config = $ config ;
43
+ $ this ->scopeConfig = $ scopeConfig ;
30
44
}
31
45
32
46
/**
@@ -38,4 +52,9 @@ public function isFullPageCacheEnabled(): bool
38
52
{
39
53
return $ this ->config ->isEnabled ();
40
54
}
55
+
56
+ public function isPaginationCacheEnabled (): bool
57
+ {
58
+ return $ this ->scopeConfig ->isSetFlag (self ::XML_PATH_CATALOG_REMEMBER_PAGINATION );
59
+ }
41
60
}
Original file line number Diff line number Diff line change @@ -7,7 +7,9 @@ if ($block->getFormKeyProvider()->isFullPageCacheEnabled()): ?>
7
7
<script type="text/x-magento-init">
8
8
{
9
9
"*": {
10
- "Magento_PageCache/js/form-key-provider": {}
10
+ "Magento_PageCache/js/form-key-provider": {
11
+ "isPaginationCacheEnabled": <?= /* @noEscape */ $ block ->getFormKeyProvider ()->isPaginationCacheEnabled () ?>
12
+ }
11
13
}
12
14
}
13
15
</script>
Original file line number Diff line number Diff line change 5
5
define ( function ( ) {
6
6
'use strict' ;
7
7
8
- return function ( ) {
8
+ return function ( settings ) {
9
9
var formKey ,
10
10
inputElements ,
11
11
inputSelector = 'input[name="form_key"]' ;
@@ -82,8 +82,13 @@ define(function () {
82
82
function initFormKey ( ) {
83
83
formKey = getFormKeyCookie ( ) ;
84
84
85
+ if ( settings . isPaginationCacheEnabled && ! formKey ) {
86
+ formKey = getFormKeyFromUI ( ) ;
87
+ setFormKeyCookie ( formKey ) ;
88
+ }
89
+
85
90
if ( ! formKey ) {
86
- formKey = getFormKeyFromUI ( ) || generateFormKeyString ( ) ;
91
+ formKey = generateFormKeyString ( ) ;
87
92
setFormKeyCookie ( formKey ) ;
88
93
}
89
94
inputElements = document . querySelectorAll ( inputSelector ) ;
You can’t perform that action at this time.
0 commit comments