Exemplo n.º 1
0
        public void ExecuteAction(OrderCalculationContext context, IWorkflowProcessorContext processorContext)
        {
            var buyGetPromotions = context.ActivePromotions.Where(p => p is BuyXGetYPromotion)
                                   .Select(p => (BuyXGetYPromotion)p);
            var notPromoProducts      = context.OrderToProducts.ToList();
            var appliedPromotionInfos = new List <Tuple <BuyXGetYPromotion, int> >();

            foreach (var promotion in buyGetPromotions)
            {
                var useCount = GetPossiableNumberOfUse(promotion, notPromoProducts);
                if (promotion.ApplyLimit.HasValue)
                {
                    useCount = Math.Min(useCount, promotion.ApplyLimit.Value);
                }

                if (useCount > 0)
                {
                    appliedPromotionInfos.Add(new Tuple <BuyXGetYPromotion, int>(promotion, useCount));
                }
            }

            if (appliedPromotionInfos.Count > 0)
            {
                var productIds     = appliedPromotionInfos.SelectMany(p => p.Item1.GetItems).Select(p => p.IdProduct).ToList();
                var productService = processorContext.Resolve <IProductService>();
                var products       = productService.GetProducts(productIds, true);
                SetPricesForPromoProducts(context, products, appliedPromotionInfos);
            }
        }
Exemplo n.º 2
0
        public void ExecuteAction(OrderCalculationContext context, IWorkflowProcessorContext processorContext)
        {
            var promotionService = processorContext.Resolve <IPromotionService>();

            context.ActivePromotions = promotionService.GetPromotions().Where(p =>
                                                                              (!p.StartDate.HasValue || p.StartDate.Value <= DateTime.Now) &&
                                                                              (!p.EndDate.HasValue || p.EndDate.Value >= DateTime.Now)).ToList();
        }
        public void ExecuteAction(OrderCalculationContext context, IWorkflowProcessorContext processorContext)
        {
            var productsInOrderWithoutPromotions = context.SourceOrder.OrderToProducts.
                                                   Where(p => !p.IdUsedBuyGetPromotion.HasValue).ToList();

            var productService = processorContext.Resolve <IProductService>();
            var products       = productService.GetProducts(productsInOrderWithoutPromotions.Select(p => p.IdProduct).ToList());

            foreach (var item in productsInOrderWithoutPromotions)
            {
                var product = products.FirstOrDefault(p => p.Id == item.IdProduct);
                if (product != null)
                {
                    var orderToProduct = new OrderToProduct();
                    orderToProduct.IdProduct = item.IdProduct;
                    orderToProduct.QTY       = item.QTY;
                    orderToProduct.Price     = product.Price;
                    context.OrderToProducts.Add(orderToProduct);
                }
            }
        }