Skip to content

Instantly share code, notes, and snippets.

@pencilcheck
Created March 25, 2017 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pencilcheck/6761a6a0fb8ae1c840052c5bd471df1d to your computer and use it in GitHub Desktop.
Save pencilcheck/6761a6a0fb8ae1c840052c5bd471df1d to your computer and use it in GitHub Desktop.
var itemCount = getCookie("itemCount");
if (itemCount !== "") {
$(".cart").text("(" + itemCount + ")");
}
function addToCart(btn, itemCode) {
addToCartApi(btn, itemCode);
if (btn) {
$(btn).text("Adding...");
$(btn).addClass('disabled');
}
}
function addToCartApi(btn, itemCode) {
$.ajax({
url: "https://evrapi.calcpa.org/api/evr/pendingCart/addItems?itemCodes=" + itemCode,
type: "POST",
dataType: 'json',
xhrFields: {
withCredentials: true
}
})
.done(function (data) {
if (btn) {
$(btn).text("In Cart");
$(btn).addClass('disabled');
}
$(".cart").text("(" + data.result.itemCount + ")");
$("#dialog-message .item-count").text(data.result.itemCount);
$("#dialog-message .item-code").text(itemCode);
// document.cookie = "itemCodes=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
// $("#dialog-adding").dialog("destroy");
$("#dialog-message")
.dialog(
{
width: 735,
height: 235,
buttons:
[
{
id: "continueShopping",
text: "Keep Shopping",
click: function () {
$("#dialog-message").dialog("destroy");
}
},
{
id: "checkoutNow",
text: "Checkout",
click: function () {
// document.cookie = "checkout=true;domain=calcpa.org;path=/";
location.href = "https://evrapp.calcpa.org/app/evr2/index.html#/cart";
$("#dialog-message").dialog("destroy");
}
}
]
});
});
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment