...
If the URL contains the “returnToken” parameter then call retrieve the cart by either specifying the query parameter “returnToken” of the request header of “X-UC-Return-Token” when retrieving the cart.
Pro-Tip
...
Example JavaScript Code to Read “returnToken” parameter from the URL
This function will return an object where the keys are the parameters on the URL, all properly decoded.
Code Block | ||
---|---|---|
| ||
function getParametersObject(url) {
if (!url) url = location.href;
var question = url.indexOf("?");
var hash = url.indexOf("#");
if (hash == -1 && question == -1) return {};
if (hash == -1) hash = url.length;
var query = question == -1 || hash == question + 1 ? url.substring(hash) :
url.substring(question + 1, hash);
var result = {};
query.split("&").forEach(function (part) {
if (!part) return;
part = part.split("+").join(" "); // replace every + with space, regexp-free version
var eq = part.indexOf("=");
var key = eq > -1 ? part.substr(0, eq) : part;
var val = eq > -1 ? decodeURIComponent(part.substr(eq + 1)) : "";
var from = key.indexOf("[");
if (from == -1) result[decodeURIComponent(key)] = val;
else {
var to = key.indexOf("]", from);
var index = decodeURIComponent(key.substring(from + 1, to));
key = decodeURIComponent(key.substring(0, from));
if (!result[key]) result[key] = [];
if (!index) result[key].push(val);
else result[key][index] = val;
}
});
return result;
}
|
Example of calling the method above and checking for the return token.
Code Block | ||
---|---|---|
| ||
var params = getParametersObject();
if (params.returnToken) {
// Fetch your cart with the return token
} |