Skip to content

Instantly share code, notes, and snippets.

@jeffdrumgod
Created October 11, 2013 23:36
Show Gist options
  • Save jeffdrumgod/6943658 to your computer and use it in GitHub Desktop.
Save jeffdrumgod/6943658 to your computer and use it in GitHub Desktop.
Obter cookie do checkout Vtex. Utiliza função para obter o parâmetro salvo no cookie checkout.vtex.com. Com este cookie podemos utilizar a api do checkout para adicionar produtos e realizar outras operações no mesmo checkout da sessão do usuário
/* http://stackoverflow.com/questions/979975/how-to-get-the-value-from-url-parameter */
function getQueryParams(qs) {
var qs = qs.split("+").join(" "), params = {}, tokens, re = /[?&]?([^=]+)=([^&]*)/g;
while (tokens = re.exec(qs)) {
params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
}
return params;
}
// obtem ID da sessão do checkout
function get_VtexCheckout_orderFormId() {
if ("undefined" !== typeof $.cookie) {
var a = $.cookie("checkout.vtex.com");
if (a !== null) {
a = getQueryParams(a);
if ("undefined" !== a.__ofid) {
return a.__ofid;
}
}
} else {
return "";
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment