Skip to content

Instantly share code, notes, and snippets.

@derekpeterson
Last active December 21, 2015 14:48
Show Gist options
  • Save derekpeterson/6322209 to your computer and use it in GitHub Desktop.
Save derekpeterson/6322209 to your computer and use it in GitHub Desktop.
Amazon Fresh demonstrating how not to do it
function updateAddAllToCartButton(event) {
var validList = "";
var invalidList = "";
jQuery(".listItem").each(function(index) {
var item = jQuery(this);
var conflictInput = item.find("input[name='conflictWithSlot']");
if (item.find(".itemUnavailableText").size() > 0 || item.find(".discontinued").size() > 0) {
// Ignore unavailable and discontinued items
} else if (conflictInput.size() == 0 || conflictInput.val() == "false") { // skip invalid items
var quantity = item.find(".addToCart input[name='quantity']");
if (quantity.size() > 0) {
var asin = item.attr("id");
var merchantId = item.find(".addToCart input[name='merchantId']").val();
validList += asin + "|" + quantity.val() + "|" + merchantId + ",";
}
} else {
invalidList +="<li>" + item.find(".itemTitle a").html() + "</li>";
}
});
jQuery(this).find("input[name='itemDetails']").val(validList);
// show message if invalid items cannot be added
if (warnOfInvalidItems && invalidList != "") {
event.preventDefault();
var message = "These items are not available for delivery <strong>" + jQuery("#headerNav #selectday a").html() + "</strong> and will NOT be added to your cart:<ul>";
message += invalidList;
message +="</ul>";
message += "<button id='addAllAvailableItemsToCart'>Continue without These Items</button>&nbsp;&nbsp;";
message += "<button class='nevermind'>Nevermind</button/>";
showOnDemandLightboxWithContent(message, jQuery(this));
jQuery("#addAllAvailableItemsToCart").click(function() {
warnOfInvalidItems = false;
jQuery("#addAllToCart").submit();
hideLightbox();
});
}
warnOfInvalidItems = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment