static public Decimal GetQuantityDiscountTablePercentageForLineItem(CartItem item, out QuantityDiscountType DiscountType) { if (!AppLogic.AppConfigBool("QuantityDiscount.CombineQuantityByProduct")) { return(GetQuantityDiscountTablePercentage(item.ThisCustomer.CustomerID, item.ProductID, item.Quantity, out DiscountType)); } if (item.ThisShoppingCart.CartItems.Count < 1) { throw new ArgumentException("cart items must be greater than 0."); } int quan = 0; foreach (CartItem c in item.ThisShoppingCart.CartItems) { if (c.ProductID == item.ProductID) { quan += c.Quantity; } } return(GetQuantityDiscountTablePercentage(item.ThisCustomer.CustomerID, item.ProductID, quan, out DiscountType)); }
/// <summary> /// Returns the Quantity Discount Percent for the specified product and quantity /// </summary> /// <param name="productId">The product ID to evaluate</param> /// <param name="quantity">The quantity value to evaluate</param> /// <returns></returns> static private Decimal GetQuantityDiscountTablePercentage(int customerId, int productId, int quantity, out QuantityDiscountType discountType) { discountType = QuantityDiscountType.Percentage; if (productId == 0) { return(0M); } var customer = new Customer(customerId); if (customer.CustomerLevelID > 0 && !CustomerLevelAllowsQuantityDiscounts(customer.CustomerLevelID)) { return(0M); } var retVal = 0M; var query = "select dbo.GetQtyDiscount(@productid, @qty, 0) Pct, dbo.GetQtyDiscount(@productid, @qty, 1) Amt"; var productIdParam = new[] { DB.CreateSQLParameter("@productid", SqlDbType.Int, 4, productId, ParameterDirection.Input), DB.CreateSQLParameter("@qty", SqlDbType.Int, 4, quantity, ParameterDirection.Input) }; using (var connection = new SqlConnection(DB.GetDBConn())) { connection.Open(); using (var reader = DB.GetRS(query, connection, productIdParam)) { if (!reader.Read()) { return(retVal); } var percentage = DB.RSFieldDecimal(reader, "Pct"); var amount = DB.RSFieldDecimal(reader, "Amt"); if (amount > decimal.Zero) { discountType = QuantityDiscountType.FixedAmount; retVal = amount; } else { discountType = QuantityDiscountType.Percentage; retVal = percentage; } } } return(retVal); }
static public Decimal GetQuantityDiscountTablePercentageWithoutCartAwareness(int customerId, int ProductID, int Quantity, out QuantityDiscountType DiscountType) { return(GetQuantityDiscountTablePercentage(customerId, ProductID, Quantity, out DiscountType)); }
/// <summary> /// Returns the Quantity Discount Percent for the specified product and quantity /// </summary> /// <param name="ProductID">The product ID to evaluate</param> /// <param name="Quantity">The quantity value to evaluate</param> /// <returns></returns> static private Decimal GetQuantityDiscountTablePercentage(int ProductID, int Quantity, out QuantityDiscountType DiscountType) { Decimal tmp = 0.0M; DiscountType = QuantityDiscountType.Percentage; if (ProductID != 0) { SqlParameter[] spa = { DB.CreateSQLParameter("@productid", SqlDbType.Int, 4, ProductID, ParameterDirection.Input), DB.CreateSQLParameter("@qty", SqlDbType.Int, 4, Quantity, ParameterDirection.Input) }; using (SqlConnection con = new SqlConnection(DB.GetDBConn())) { con.Open(); using (IDataReader rs = DB.GetRS("select dbo.GetQtyDiscount(@productid, @qty, 0) Pct, dbo.GetQtyDiscount(@productid, @qty, 1) Amt", spa, con)) { if (rs.Read()) { Decimal pct = DB.RSFieldDecimal(rs, "Pct"); Decimal amt = DB.RSFieldDecimal(rs, "Amt"); if (amt > decimal.Zero) { DiscountType = QuantityDiscountType.FixedAmount; tmp = amt; } else { DiscountType = QuantityDiscountType.Percentage; tmp = pct; } } } } } return(tmp); }