private ItemAvailability GetItemAvailabilityInternal(Item item, Inventory inventory) { var retVal = new ItemAvailability { MinQuantity = item.MinQuantity, MaxQuantity = item.MaxQuantity, ItemId = item.ItemId }; if (item.IsBuyable && item.StartDate < CustomerSession.CurrentDateTime && (!item.EndDate.HasValue || item.EndDate > CustomerSession.CurrentDateTime)) { if (item.TrackInventory) { if (inventory != null && (InventoryStatus)inventory.Status == InventoryStatus.Enabled) { var inStock = inventory.InStockQuantity - inventory.ReservedQuantity; if (inStock > 0 && (item.AvailabilityRule == (int)AvailabilityRule.Always || item.AvailabilityRule == (int)AvailabilityRule.WhenInStock)) { retVal.MaxQuantity = inStock; retVal.Availability = ItemStoreAvailabity.InStore; retVal.MaxQuantity = Math.Max(retVal.MinQuantity, retVal.MaxQuantity); retVal.MinQuantity = Math.Min(retVal.MinQuantity, retVal.MaxQuantity); return retVal; } if (inventory.AllowBackorder && inventory.BackorderAvailabilityDate.HasValue && (item.AvailabilityRule == (int)AvailabilityRule.Always || item.AvailabilityRule == (int)AvailabilityRule.OnBackorder)) { retVal.MaxQuantity = inStock + inventory.BackorderQuantity; if (retVal.MaxQuantity > 0) { retVal.Availability = ItemStoreAvailabity.AvailableForBackOrder; retVal.Date = inventory.BackorderAvailabilityDate; retVal.MaxQuantity = Math.Max(retVal.MinQuantity, retVal.MaxQuantity); retVal.MinQuantity = Math.Min(retVal.MinQuantity, retVal.MaxQuantity); return retVal; } } if (inventory.AllowPreorder && inventory.PreorderAvailabilityDate.HasValue) { retVal.MaxQuantity = inventory.PreorderQuantity; if (retVal.MaxQuantity > 0 && (item.AvailabilityRule == (int)AvailabilityRule.Always || item.AvailabilityRule == (int)AvailabilityRule.OnPreorder)) { retVal.Availability = ItemStoreAvailabity.AvailableForPreOrder; retVal.Date = inventory.PreorderAvailabilityDate; retVal.MaxQuantity = Math.Max(retVal.MinQuantity, retVal.MaxQuantity); retVal.MinQuantity = Math.Min(retVal.MinQuantity, retVal.MaxQuantity); return retVal; } } } } else { retVal.MaxQuantity = item.MaxQuantity; if (retVal.MaxQuantity > 0 && (item.AvailabilityRule == (int)AvailabilityRule.Always || item.AvailabilityRule == (int)AvailabilityRule.WhenInStock)) { retVal.Availability = ItemStoreAvailabity.InStore; } retVal.MaxQuantity = Math.Max(retVal.MinQuantity, retVal.MaxQuantity); retVal.MinQuantity = Math.Min(retVal.MinQuantity, retVal.MaxQuantity); } } return retVal; }
/// <summary> /// Initializes a new instance of the <see cref="ItemAvailabilityModel"/> class. /// </summary> /// <param name="availability">The availability.</param> public ItemAvailabilityModel(ItemAvailability availability) { _availability = availability; }
private ItemAvailability GetItemAvailabilityInternal(Item item, Inventory inventory) { var retVal = new ItemAvailability { MinQuantity = item.MinQuantity, MaxQuantity = item.MaxQuantity, ItemId = item.ItemId }; if (item.IsBuyable && item.StartDate < CustomerSession.CurrentDateTime && (!item.EndDate.HasValue || item.EndDate > CustomerSession.CurrentDateTime)) { if (item.TrackInventory) { if (inventory != null && (InventoryStatus)inventory.Status == InventoryStatus.Enabled) { var inStock = inventory.InStockQuantity - inventory.ReservedQuantity; if (inStock > 0 && (item.AvailabilityRule == (int)AvailabilityRule.Always || item.AvailabilityRule == (int)AvailabilityRule.WhenInStock)) { retVal.MaxQuantity = inStock; retVal.Availability = ItemStoreAvailabity.InStore; retVal.MaxQuantity = Math.Max(retVal.MinQuantity, retVal.MaxQuantity); retVal.MinQuantity = Math.Min(retVal.MinQuantity, retVal.MaxQuantity); return(retVal); } if (inventory.AllowBackorder && inventory.BackorderAvailabilityDate.HasValue && (item.AvailabilityRule == (int)AvailabilityRule.Always || item.AvailabilityRule == (int)AvailabilityRule.OnBackorder)) { retVal.MaxQuantity = inStock + inventory.BackorderQuantity; if (retVal.MaxQuantity > 0) { retVal.Availability = ItemStoreAvailabity.AvailableForBackOrder; retVal.Date = inventory.BackorderAvailabilityDate; retVal.MaxQuantity = Math.Max(retVal.MinQuantity, retVal.MaxQuantity); retVal.MinQuantity = Math.Min(retVal.MinQuantity, retVal.MaxQuantity); return(retVal); } } if (inventory.AllowPreorder && inventory.PreorderAvailabilityDate.HasValue) { retVal.MaxQuantity = inventory.PreorderQuantity; if (retVal.MaxQuantity > 0 && (item.AvailabilityRule == (int)AvailabilityRule.Always || item.AvailabilityRule == (int)AvailabilityRule.OnPreorder)) { retVal.Availability = ItemStoreAvailabity.AvailableForPreOrder; retVal.Date = inventory.PreorderAvailabilityDate; retVal.MaxQuantity = Math.Max(retVal.MinQuantity, retVal.MaxQuantity); retVal.MinQuantity = Math.Min(retVal.MinQuantity, retVal.MaxQuantity); return(retVal); } } } } else { retVal.MaxQuantity = item.MaxQuantity; if (retVal.MaxQuantity > 0 && (item.AvailabilityRule == (int)AvailabilityRule.Always || item.AvailabilityRule == (int)AvailabilityRule.WhenInStock)) { retVal.Availability = ItemStoreAvailabity.InStore; } retVal.MaxQuantity = Math.Max(retVal.MinQuantity, retVal.MaxQuantity); retVal.MinQuantity = Math.Min(retVal.MinQuantity, retVal.MaxQuantity); } } return(retVal); }