Skip to content

Commit 82b4822

Browse files
committed
MAGE-1101: Update getCookie method to handle multiple cookie values
1 parent d61d854 commit 82b4822

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

view/frontend/web/js/internals/common.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,26 @@ define(['jquery', 'algoliaBundle'], function ($, algoliaBundle) {
9898
return check;
9999
};
100100

101-
window.getCookie = function (name) {
102-
var value = "; " + document.cookie;
103-
var parts = value.split("; " + name + "=");
104-
if (parts.length == 2) {
105-
return parts.pop().split(";").shift();
101+
window.getCookie = function(name) {
102+
var cookie,
103+
i,
104+
cookieName = name + "=",
105+
cookieArr = document.cookie.split(';');
106+
107+
for (i = 0; i < cookieArr.length; i++) {
108+
cookie = cookieArr[i];
109+
110+
while (cookie.charAt(0) === ' ') {
111+
cookie = cookie.substring(1, cookie.length);
112+
}
113+
114+
if (cookie.indexOf(cookieName) === 0) {
115+
return cookie.substring(cookieName.length, cookie.length);
116+
}
106117
}
107118

108119
return "";
109-
};
120+
}
110121

111122
window.transformHit = function (hit, price_key, helper) {
112123
if (Array.isArray(hit.categories))

0 commit comments

Comments
 (0)