public PromotionResult ApplyPromotion(IEnumerable <IOrderItem> orderItems)
        {
            var result = PromotionResult.Failure();

            var skuOrderItem = GetFirstApplicableOrderItem(orderItems);

            if (skuOrderItem != null)
            {
                var fixedPriceMultiplier = skuOrderItem.Count / _count;
                var fullPriceMultiplier  = skuOrderItem.Count % _count;
                var adjustmentAmount     = skuOrderItem.Amount - (fixedPriceMultiplier * _fixedPrice + fullPriceMultiplier * skuOrderItem.SKU.UnitPrice);
                var adjustmentOrderItem  = new PromotionAdjustmentOrderItem(-adjustmentAmount);
                return(PromotionResult.Success(adjustmentOrderItem, new ISKU[] { skuOrderItem.SKU }));
            }
            return(result);
        }
예제 #2
0
        public PromotionResult ApplyPromotion(IEnumerable <IOrderItem> orderItems)
        {  // assumption: max 1 order item per SKU
            var result = PromotionResult.Failure();

            var relevantOrderItems = orderItems.OfType <ISKUOrderItem>()
                                     .Where(x => _skuIdCombination.Contains(x.SKU.ID))
                                     .ToList();

            if (relevantOrderItems.Count == _skuIdCombination.Count)
            {
                var combinedUnitPriceBeforeAdjustment = relevantOrderItems.Sum(x => x.SKU.UnitPrice);
                var adjustment     = combinedUnitPriceBeforeAdjustment - _fixedPrice;
                var adjustmentItem = new PromotionAdjustmentOrderItem(-adjustment);
                return(PromotionResult.Success(adjustmentItem, relevantOrderItems.Select(x => x.SKU)));
            }
            return(result);
        }