/// <summary> /// Gets all discounts /// </summary> /// <param name="DiscountType">Discount type; null to load all discount</param> /// <returns>Discount collection</returns> public static DiscountCollection GetAllDiscounts(DiscountTypeEnum?DiscountType) { bool showHidden = NopContext.Current.IsAdmin; string key = string.Format(DISCOUNTS_ALL_KEY, showHidden, DiscountType); object obj2 = NopCache.Get(key); if (DiscountManager.CacheEnabled && (obj2 != null)) { return((DiscountCollection)obj2); } int?discountTypeID = null; if (DiscountType.HasValue) { discountTypeID = (int)DiscountType.Value; } DBDiscountCollection dbCollection = DBProviderManager <DBDiscountProvider> .Provider.GetAllDiscounts(showHidden, discountTypeID); DiscountCollection discounts = DBMapping(dbCollection); if (DiscountManager.CacheEnabled) { NopCache.Max(key, discounts); } return(discounts); }
private static DiscountCollection DBMapping(DBDiscountCollection dbCollection) { if (dbCollection == null) { return(null); } DiscountCollection collection = new DiscountCollection(); foreach (DBDiscount dbItem in dbCollection) { Discount item = DBMapping(dbItem); collection.Add(item); } return(collection); }
/// <summary> /// Gets a preferred discount /// </summary> /// <param name="Discounts">Discounts to analyze</param> /// <param name="Amount">Amount</param> /// <returns>Preferred discount</returns> public static Discount GetPreferredDiscount(DiscountCollection Discounts, decimal Amount) { Discount preferredDiscount = null; decimal maximumDiscountValue = decimal.Zero; foreach (Discount _discount in Discounts) { decimal currentDiscountValue = _discount.GetDiscountAmount(Amount); if (currentDiscountValue > maximumDiscountValue) { maximumDiscountValue = currentDiscountValue; preferredDiscount = _discount; } } return(preferredDiscount); }
/// <summary> /// Gets a discount collection of a category /// </summary> /// <param name="CategoryID">Category identifier</param> /// <returns>Discount collection</returns> public static DiscountCollection GetDiscountsByCategoryID(int CategoryID) { bool showHidden = NopContext.Current.IsAdmin; string key = string.Format(DISCOUNTS_BY_CATEGORYID_KEY, CategoryID, showHidden); object obj2 = NopCache.Get(key); if (DiscountManager.CacheEnabled && (obj2 != null)) { return((DiscountCollection)obj2); } DBDiscountCollection dbCollection = DBProviderManager <DBDiscountProvider> .Provider.GetDiscountsByCategoryID(CategoryID, showHidden); DiscountCollection discounts = DBMapping(dbCollection); if (DiscountManager.CacheEnabled) { NopCache.Max(key, discounts); } return(discounts); }
/// <summary> /// Get a value indicating whether discounts that require coupon code exist /// </summary> /// <returns>A value indicating whether discounts that require coupon code exist</returns> public static bool HasDiscountsWithCouponCode() { DiscountCollection discounts = GetAllDiscounts(null); return(discounts.Find(d => d.RequiresCouponCode) != null); }