Skip to content

Commit 64131ca

Browse files
committed
Get back custom getCookieValue js function
1 parent b40fa05 commit 64131ca

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

view/frontend/templates/js_code.phtml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ if (!isset($escaper)) {
1717

1818
$script = '';
1919
?>
20-
21-
<?= $block->getLayout()->createBlock(\Magefan\Community\Block\JsScript::class)->setMethod('getCookie')->toHtml() ?>
22-
2320
<!-- Google Tag Manager -->
2421
<?php if ($block->isSpeedOptimizationEnabled() && $block->getRequest()->getModuleName() !== 'checkout') { ?>
2522
<?php $script .= "
@@ -43,8 +40,8 @@ $script = '';
4340

4441
<?php if ($block->isProtectCustomerDataEnabled()) { ?>
4542
<?php
46-
if (!$block->isMfCookieConsentExtensionEnabled()) {
47-
$script .= "
43+
if (!$block->isMfCookieConsentExtensionEnabled()) {
44+
$script .= "
4845
window.dataLayer = window.dataLayer || [];
4946
function gtag() { dataLayer.push(arguments); }
5047
gtag('consent', 'default', {
@@ -66,7 +63,7 @@ $script = '';
6663
gtag('set', 'url_passthrough', true);
6764
/* cookieyes.com end */
6865
";
69-
}
66+
}
7067
?>
7168

7269
<?php if ($block->isLoadBeforeConsent()) { ?>
@@ -79,12 +76,29 @@ $script = '';
7976
<?php if ($block->isCookieRestrictionModeEnabled()) { ?>
8077
<?php $script .= "
8178
(function () {
79+
function getCookieValue(cookieName) {
80+
let name = cookieName + '=';
81+
let cookieSplit = document.cookie.split(';');
82+
83+
for (let i = 0; i < cookieSplit.length; i++) {
84+
let a = cookieSplit[i];
85+
86+
while (a.charAt(0) === ' ') {
87+
a = a.substring(1);
88+
}
89+
90+
if (a.indexOf(name) === 0) {
91+
return a.substring(name.length, a.length);
92+
}
93+
}
94+
return '';
95+
};
8296
8397
function customerDataAllowed() {
84-
if (MagefanJs.getCookie('mf_cookie_consent')) {
98+
if (getCookieValue('mf_cookie_consent')) {
8599
return true;
86100
};
87-
let cookie = MagefanJs.getCookie(
101+
let cookie = getCookieValue(
88102
'{$escaper->escapeHtml(\Magento\Cookie\Helper\Cookie::IS_USER_ALLOWED_SAVE_COOKIE)}'
89103
);
90104
if (cookie) {
@@ -102,8 +116,8 @@ $script = '';
102116
window.mfGtmUserCookiesAllowed = true;
103117
";
104118

105-
if (!$block->isMfCookieConsentExtensionEnabled()) {
106-
$script .= "gtag('consent', 'update', {
119+
if (!$block->isMfCookieConsentExtensionEnabled()) {
120+
$script .= "gtag('consent', 'update', {
107121
'ad_user_data': 'granted',
108122
'ad_personalization': 'granted',
109123
'ad_storage': 'granted',
@@ -112,9 +126,9 @@ $script = '';
112126
'personalization_storage': 'granted',
113127
'security_storage': 'granted'
114128
});";
115-
}
129+
}
116130

117-
$script .= "
131+
$script .= "
118132
};
119133
120134
if (customerDataAllowed()) {

0 commit comments

Comments
 (0)