Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.