Esempio n. 1
0
        private IEnumerable <Rule> ConvertBaskets(Dictionary <string, string> hierarchyMapping, DBReader dbReader, RuleConverter.Data.Model model, ProductModel pm)
        {
            var basketParser     = new BasketParser(hierarchyMapping, pm);
            var extractedBaskets = dbReader.GetBaskets(model);
            var convertedBaskets = basketParser.ConvertBaskets(extractedBaskets);

            return(convertedBaskets.Select(r => new Rule(r.Name, r.Expression, null, EnabledFlag.True)));
        }
Esempio n. 2
0
        /// <summary>
        /// Main basket items processing method. It's idemopotent.
        /// </summary>
        public void Checkout()
        {
            SkuEntity     skuEntity;
            IBasketParser basketParser = BasketParser.Create(basketFilePath);

            receiptLineItems = new List <Entities.LineItem>();

            // Iterate through each item in the basket
            while (basketParser.MoveNext())
            {
                basketItem = basketParser.Current;

                skuEntity = this.catalogModel.Find(basketItem.Sku);

                if (skuEntity != null)
                {
                    // Add regular line item
                    receiptLineItems.Add(new LineItem
                    {
                        LineItemType = DiscountTypes.noDiscount,
                        Label        = skuEntity.Label,
                        Price        = skuEntity.Price,
                        Qty          = basketItem.Qty,
                        Sku          = skuEntity.Id,
                        Total        = basketItem.Qty * skuEntity.Price
                    });

                    // Add discount line item (automatically determined by the appropriate discount strategy for the item)
                    IDiscountStrategy discountStrategy
                        = DiscountStrategy.Instance.Create(skuEntity.DiscountType);

                    // Create the discount line item if any
                    LineItem discountLineItem =
                        discountStrategy.GenerateDiscountLineItem(skuEntity, basketItem);

                    if (discountLineItem != null)
                    {
                        receiptLineItems.Add(discountLineItem);
                    }
                }
            }

            // Reset discount strategies to get them ready for next basket checkout
            DiscountStrategy.Instance.Reset();
        }
Esempio n. 3
0
        static int Main(string[] args)
        {
            var basketParser = new BasketParser(new Inventory());

            var(items, failed) = basketParser.ParseBasket(args);
            if (failed.Any())
            {
                Console.WriteLine("Could not parse input:");
                foreach (var error in failed)
                {
                    Console.WriteLine($"Item {error} not in inventory");
                }
                return(1);
            }
            var pricing = new Pricing(new Offers());
            var price   = pricing.CalculatePrice(items);
            var lines   = new PriceFormatter().Format(price);

            foreach (var line in lines)
            {
                Console.WriteLine(line);
            }
            return(0);
        }