$(document).ready(function() { //Add Inventory section/table to the page, hide for now $('<div class="inventory"><h3>Inventory:</h3><table class="table table-striped table-condensed inventory-table"><thead><th>Name</th><th>On Order</th><th>On Hand</th><th>Available</th></thead><tbody></tbody></table></div>').appendTo('.page-productdetails #upnlPreviews').hide(); }); function dmLoad() { // Check if this product is listed in Inventory, if so run function var inventoryItem = $(".page-productdetails #lblItemName").text(); var portalIdentity = new URLSearchParams(window.location.search).get('PortalId'); $(".page-productdetails .inventory-table tbody").load(("/Inventory.aspx?PortalId=" + portalIdentity + " .inside-page-content tr:contains('" + inventoryItem + "')"), null, function() { // Set variable "availableQuantity" to text of last column in inventory table $(".page-productdetails .inventory-table td:last-child").addClass("available"); // If this product is listed in Inventory, the class "available" will be on the page, set conditions if ($(".available")[0]) { // Show Inventory section/table $(".inventory").show(); } }); }
.disabled2 { pointer-events: none !important; cursor: not-allowed !important; filter: alpha(opacity=65); -webkit-box-shadow: none; box-shadow: none; opacity: .65; }
.inventory-table th:nth-child(2), .inventory-table th:nth-child(3), .inventory-table td:nth-child(2), .inventory-table td:nth-child(3) { display: none; }
$(document).ready(function() { //Add Inventory section/table to the page, hide for now $('<div class="inventory"><h3>Inventory:</h3><table class="table table-striped table-condensed inventory-table"><thead><th>Name</th><th>On Order</th><th>On Hand</th><th>Available</th></thead><tbody></tbody></table></div>').appendTo('.page-productdetails #upnlPreviews').hide(); }); function dmLoad() { // Disable Add to Cart by default $("#btnAddToCart").addClass("disabled2"); // Check if this product is listed in Inventory, if so run function var inventoryItem = $(".page-productdetails #lblItemName").text(); var portalIdentity = new URLSearchParams(window.location.search).get('PortalId'); $(".page-productdetails .inventory-table tbody").load(("/Inventory.aspx?PortalId=" + portalIdentity + " .inside-page-content tr:contains('" + inventoryItem + "')"), null, function() { // Set variable "availableQuantity" to text of last column in inventory table $(".page-productdetails .inventory-table td:last-child").addClass("available"); var availableQuantity = parseInt($(".inventory-table .available").text()); var quantity; //Set variable "selectedQuantity" to either the selected quantity in table OR value of quantity field if ($(".product-quantity-table")[0]) { quantity = parseInt($('.product-quantity-table input:checked').closest("td").next('td').find('span').text()); } else { quantity = parseInt($('#txtQuantity').val()); } // If this product is listed in Inventory, the class "available" will be on the page, set conditions if ($(".available")[0]) { // Show Inventory section/table $(".inventory").show(); // If the requested quantity is more than the available quantity, insert warning after disabled button if (quantity > availableQuantity) { $("#btnAddToCart").addClass("disabled2"); $("<div class='warning text-right'>The quantity selected is more than what we currently have available.</div>").insertAfter('#upnlPricing'); $("#btnAddToCart").val("Out of Stock"); // If not, enable the button and remove the warning } else { $("#btnAddToCart").removeClass("disabled2"); $(".warning").hide(); } // If the item is not in Inventory, enable the add to cart button } else { $("#btnAddToCart").removeClass("disabled2"); } }); }
.disabled2 { pointer-events: none !important; cursor: not-allowed !important; filter: alpha(opacity=65); -webkit-box-shadow: none; box-shadow: none; opacity: .65; } .page-productlist .product-quantities-container, .page-search .product-quantities-container, .page-favorites .product-quantities-container { display: none; }
If you have any ideas for portal customizations you'd like to see us tackle or need help implementing any of this code, email our support team at support@docketmanager.ca