public int InventoryQuantityAvailableForPurchase(Product p, string variantId) { int result = 0; if (p.InventoryMode == ProductInventoryMode.AlwayInStock) { return(9999); } List <ProductInventory> inv = ProductInventories.FindByProductId(p.Bvin); if (variantId != string.Empty) { var vi = (from pi in inv where pi.VariantId == variantId select pi).SingleOrDefault(); if (vi != null) { result = vi.QuantityAvailableForSale; } } else { // no variants result = (from pi in inv select pi).Sum(y => y.QuantityAvailableForSale); } return(result); }
public bool InventoryIsProductVisible(Catalog.Product product) { if (product.Status == ProductStatus.Disabled) { return(false); } else { if (product.InventoryMode == ProductInventoryMode.AlwayInStock) { return(true); } else { List <Catalog.ProductInventory> inv = ProductInventories.FindByProductId(product.Bvin); // no inventory info so assume it's available if (inv == null) { return(true); } if (inv.Count < 1) { return(true); } bool foundStock = false; foreach (ProductInventory piv in inv) { if (piv.InventoryEvaluateStatus(product) == ProductInventoryStatus.Available) { return(true); } else { if (product.InventoryMode != ProductInventoryMode.WhenOutOfStockHide) { return(true); } } } if (!foundStock) { return(false); } } } return(true); }
public void CleanUpInventory(Product p) { if (p == null) { return; } List <ProductInventory> allInventory = ProductInventories.FindByProductId(p.Bvin); if (allInventory == null) { return; } if (allInventory.Count < 1) { return; } if (p.HasVariants()) { foreach (ProductInventory inv in allInventory) { if (inv.VariantId.Trim() == string.Empty) { // Remove non-variant inventory levels ProductInventories.Delete(inv.Bvin); } if (p.Variants.Where(y => y.Bvin == inv.VariantId).Count() <= 0) { // Remove variant inventory levels that don't apply anymore ProductInventories.Delete(inv.Bvin); } } } else { // Remove all variant inventory levels foreach (ProductInventory inv in allInventory) { if (inv.VariantId.Trim() != string.Empty) { ProductInventories.Delete(inv.Bvin); } } } }