/// <summary> /// Gets the inventory. /// </summary> /// <param name="skuId">The sku id.</param> public void GetInventory(string skuId) { if (ThisPage.Product.AllowNegativeInventories) { ThisPage.AddToCart.Enabled = true; } else { Sku sku = ProductCache.GetSKU(skuId); if (sku.SkuId > 0 && sku.Inventory > 0) { string previouslySelectedValue = ThisPage.Quantity.SelectedValue; ThisPage.AddToCart.Enabled = true; ThisPage.Quantity.Enabled = true; ThisPage.Quantity.Items.Clear(); if (sku.Inventory < SiteSettingCache.GetSiteSettings().MaxProductsAddToCart) { for (int i = 1; i <= sku.Inventory; i++) { ThisPage.Quantity.Items.Add(new ListItem(i.ToString(), i.ToString())); } } else { for (int i = 1; i <= SiteSettingCache.GetSiteSettings().MaxProductsAddToCart; i++) { ThisPage.Quantity.Items.Add(new ListItem(i.ToString(), i.ToString())); } } //If they selected a quantity and the quantity is valid for the new selection then keep it selected //Otherwise, select the first one. if (ThisPage.Quantity.Items.FindByValue(previouslySelectedValue) != null) { ThisPage.Quantity.SelectedValue = previouslySelectedValue; } else { ThisPage.Quantity.SelectedIndex = 0; } } else { ThisPage.Quantity.Enabled = false; ThisPage.AddToCart.Enabled = false; } } }