Пример #1
0
        public override IEnumerable <Discount> Process(CartContext cart)
        {
            List <Product> purchased_items = new List <Product>(cart.GetVisiblePurchasedItems(this.ExclusiveTag));

            foreach (var d in this._discount_table)
            {
                var drinks = purchased_items.Where(p => p.Tags.Contains(d.drink)).OrderByDescending(p => p.Price).ToArray();
                var foods  = purchased_items.Where(p => p.Tags.Contains(d.food)).OrderByDescending(p => p.Price).ToArray();

                if (drinks.Count() == 0)
                {
                    continue;
                }
                if (foods.Count() == 0)
                {
                    continue;
                }

                for (int i = 0; true; i++)
                {
                    if (drinks.Length <= i)
                    {
                        break;
                    }
                    if (foods.Length <= i)
                    {
                        break;
                    }

                    if (purchased_items.Contains(drinks[i]) == false)
                    {
                        break;
                    }
                    if (purchased_items.Contains(foods[i]) == false)
                    {
                        break;
                    }


                    purchased_items.Remove(drinks[i]);
                    purchased_items.Remove(foods[i]);
                    yield return(new Discount()
                    {
                        Rule = this,
                        Products = new Product[] { drinks[i], foods[i] },
                        Amount = drinks[i].Price + foods[i].Price - d.price
                    });
                }
            }
        }
Пример #2
0
        public override IEnumerable <Discount> Process(CartContext cart)
        {
            List <Product> matched = new List <Product>();

            foreach (var sku in cart.GetVisiblePurchasedItems(this.ExclusiveTag).Where(p => p.Tags.Contains(this.TargetTag)).Select(p => p.SKU).Distinct())
            {
                matched.Clear();
                foreach (var p in cart.GetVisiblePurchasedItems(this.ExclusiveTag).Where(p => p.SKU == sku))
                {
                    matched.Add(p);
                    if (matched.Count == 2)
                    {
                        yield return(new Discount()
                        {
                            Products = matched.ToArray(),
                            Amount = this.DiscountAmount,
                            Rule = this
                        });

                        matched.Clear();
                    }
                }
            }
        }
Пример #3
0
        public override IEnumerable <Discount> Process(CartContext cart)
        {
            List <Product> matched = new List <Product>();

            foreach (var p in cart.GetVisiblePurchasedItems(this.ExclusiveTag).Where(p => p.Tags.Contains(this.TargetTag)).OrderByDescending(p => p.Price))
            {
                matched.Add(p);
                if (matched.Count == 2)
                {
                    yield return(new Discount()
                    {
                        Amount = matched.Sum(p => p.Price) * this.PercentOff / 100,
                        Products = matched.ToArray(),
                        Rule = this
                    });

                    matched.Clear();
                }
            }
        }
Пример #4
0
        public override IEnumerable <Discount> Process(CartContext cart)
        {
            List <Product> matched_products = new List <Product>();

            foreach (var p in cart.GetVisiblePurchasedItems(this.ExclusiveTag))
            {
                matched_products.Add(p);

                if (matched_products.Count == this.BoxCount)
                {
                    // 符合折扣
                    yield return(new Discount()
                    {
                        Amount = matched_products.Select(p => p.Price).Sum() * this.PercentOff / 100,
                        Products = matched_products.ToArray(),
                        Rule = this,
                    });

                    matched_products.Clear();
                }
            }
        }