/// <summary> /// Returns discount information by ProductID /// </summary> /// <param name="productID">ProductID</param> /// <returns>ProductDiscount</returns> public static ProductDiscount GetProductDiscount(int productID) { ProductDiscount pOut = null; foreach (ProductDiscount disc in Discounts) { if (disc.ProductID == productID) { pOut = disc; break; } } return(pOut); }
/// <summary> /// Returns discount information by SKU /// </summary> /// <param name="sku">Product Sku</param> /// <returns>ProductDiscount</returns> public static ProductDiscount GetProductDiscount(string sku) { ProductDiscount pOut = null; foreach (ProductDiscount disc in Discounts) { if (disc.Sku.Trim().ToLower().Equals(sku.Trim().ToLower())) { pOut = disc; break; } } return(pOut); }
public static List <ProductDiscount> GetDiscounts() { IDataReader rdr = SPs.PromoProductMatrix().GetReader(); List <ProductDiscount> coll = new List <ProductDiscount>(); ProductDiscount disc; while (rdr.Read()) { disc = new ProductDiscount(); disc.Load(rdr); coll.Add(disc); } rdr.Close(); return(coll); }
/// <summary> /// Sets the pricing of a product according to the discounts found, and /// returns the discount information (title, etc). /// </summary> /// <param name="product"></param> /// <returns>ProductDiscount</returns> public static ProductDiscount SetProductPricing(Commerce.Common.Product product) { ProductDiscount discount = GetProductDiscount(product.ProductID); if (discount == null) { //this is a normal pricing scheme //meaning that the "everyday discount" off of retail //is in effect discount = new ProductDiscount(); discount.Title = ConfigurationManager.AppSettings["discountTitle"]; discount.Description = ConfigurationManager.AppSettings["discountDescription"]; //the price has already been set by the merchant //in the product's RetailPrice. So back-calculate it if (product.RetailPrice > 0) { discount.Discount = product.OurPrice / product.RetailPrice * 100; } discount.DiscountedPrice = product.OurPrice; discount.DiscountAmount = product.RetailPrice - product.OurPrice; } product.OurPrice = discount.DiscountedPrice; product.YouSavePrice = discount.DiscountAmount; //calc the percent saved //this is calculated as the overall savings between the //retail price, and the final discounted price decimal dSavingsRate = 1; if (product.RetailPrice != 0) { dSavingsRate = discount.DiscountedPrice / product.RetailPrice; } decimal savingsPercent = 1 - (dSavingsRate); product.YouSavePercent = Math.Round(savingsPercent, 2); return(discount); }
/// <summary> /// Resets the static Discounts property. Use when you update /// the promos from the admin section. /// </summary> public static void ResetPromos() { discounts = ProductDiscount.GetDiscounts(); }