Exemplo n.º 1
0
        internal static DiscountItem CalculateCartRuleDiscount(RenderContext context, PromotionRule rule, Cart cart)
        {
            if (rule == null || (rule.Percent == 1 && rule.Amount == 0))
            {
                return(null);
            }

            DiscountItem result = new DiscountItem();

            var reasonobj = rule.GetValue(context.Culture);

            if (reasonobj != null)
            {
                result.Reason = reasonobj.ToString();
            }

            decimal offprice = 0;

            if (rule.Percent > 0 && rule.Percent <= 1)
            {
                offprice = cart.TotalAmount * rule.Percent;
            }

            if (rule.Amount > 0)
            {
                offprice = offprice + rule.Amount;
            }

            result.Discount   = offprice;
            result.CanCombine = rule.CanCombine;
            return(result);
        }
Exemplo n.º 2
0
        public static Discount CombineDiscountRules(Discount discount)
        {
            var exclusiveItems = discount.items.FindAll(o => o.CanCombine == false);

            if (exclusiveItems != null && exclusiveItems.Any())
            {
                // rule one, remove other.
                discount.items.RemoveAll(o => o.CanCombine);
                DiscountItem highestvalue = null;
                foreach (var item in discount.items)
                {
                    if (highestvalue == null)
                    {
                        highestvalue = item;
                    }
                    else
                    {
                        if (highestvalue.Total < item.Total)
                        {
                            highestvalue = item;
                        }
                    }
                }

                discount.items.Clear();
                if (highestvalue != null)
                {
                    discount.items.Add(highestvalue);
                }
            }

            return(discount);
        }
Exemplo n.º 3
0
        internal static DiscountItem CalculateCartItemRuleDiscount(RenderContext context, PromotionRule rule, CartItem item)
        {
            if (rule == null || (rule.Percent == 1 && rule.Amount == 0))
            {
                return(null);
            }


            decimal offprice = 0;

            if (rule.Percent > 0 && rule.Percent < 1)
            {
                offprice = item.UnitPrice * rule.Percent;
            }

            if (rule.Amount > 0)
            {
                offprice = offprice + rule.Amount;
            }

            if (offprice <= 0)
            {
                return(null);
            }

            DiscountItem result = new DiscountItem();

            var reasonobj = rule.GetValue(context.Culture);

            if (reasonobj != null)
            {
                result.Reason = reasonobj.ToString();
            }

            result.Discount = offprice;

            result.RuleId = rule.Id;

            result.Quantity   = item.Quantity;
            result.CanCombine = rule.CanCombine;
            return(result);
        }