public override void ClearPromotionResult(CustomerOrder customerOrder) { List <OrderLine> list = customerOrder.OrderLines.Where <OrderLine>((Func <OrderLine, bool>)(o => { if (o.CustomProperties.Where(x => x.Name.EqualsIgnoreCase("IsSubscriptionOpted")).Count() > 0) { var IsSubscriptionOpted = o.CustomProperties.FirstOrDefault(x => x.Name.EqualsIgnoreCase("IsSubscriptionOpted")).Value; if (!string.IsNullOrEmpty(o.CostCode)) { return(true); } } return(false); })).ToList <OrderLine>(); if (!list.Any <OrderLine>()) { return; } foreach (OrderLine orderLine in list) { orderLine.PromotionResult = (PromotionResult)null; } ProductPromotionHelper_Brasseler helper = new ProductPromotionHelper_Brasseler(this.pricingPipeline, this.promotionAmountProvider); IDictionary <Guid, ProductPriceDto> pricingServiceResult = helper.GetPricingServiceResult((IEnumerable <OrderLine>)list); foreach (OrderLine orderLine1 in list) { OrderLine orderLine = orderLine1; ProductPriceDto productPriceDto = pricingServiceResult.First <KeyValuePair <Guid, ProductPriceDto> >((Func <KeyValuePair <Guid, ProductPriceDto>, bool>)(o => o.Key == orderLine.Id)).Value; orderLine.CostCode = string.Empty; orderLine.UnitNetPrice = productPriceDto.UnitRegularPrice; } //TOBEREMOVED //.ForEach((Action<OrderLine>)(orderLine => //{ // //orderLine.PromotionResult = (PromotionResult)null; // orderLine.CostCode = string.Empty; // IDictionary<Guid, ProductPriceDto> productPriceDto = GetPricingServiceResult((IEnumerable<OrderLine>) orderLine); // orderLine.UnitNetPrice = productPriceDto.FirstOrDefault().Value.UnitRegularPrice; //})); }
protected virtual void ApplyDiscountToOrderLines(PromotionResult promotionResult, OrderLine orderLine, CustomerOrder customerOrder) { CustomerOrderPromotion appliedPromotion = customerOrder.CustomerOrderPromotions.FirstOrDefault <CustomerOrderPromotion>((Func <CustomerOrderPromotion, bool>)(p => p.PromotionId == promotionResult.PromotionId)); List <OrderLine> list = new List <OrderLine>(); list.Add(orderLine); if (SiteContext.Current != null && SiteContext.Current.ShipTo != null) { if (string.IsNullOrEmpty(orderLine.CostCode)) { //orderLine.PromotionResult = promotionResult; ProductPromotionHelper_Brasseler helper = new ProductPromotionHelper_Brasseler(this.pricingPipeline, this.promotionAmountProvider); IDictionary <Guid, ProductPriceDto> pricingServiceResult = helper.GetPricingServiceResult((IEnumerable <OrderLine>)list); ProductPriceDto productPriceDto = pricingServiceResult.First(o => o.Key == orderLine.Id).Value; Decimal UnitNetPrice = orderLine.UnitNetPrice; // Check current flow of Customer. HelperUtility helperUtility = new HelperUtility(); var currentCustomer = helperUtility.GetCurrentCustomerFlow(customerOrder); if (currentCustomer.CustomProperties.Where(x => x.Name.EqualsIgnoreCase("SubscriptionDiscount")).Count() > 0) { var amount = currentCustomer.CustomProperties.FirstOrDefault(x => x.Name.EqualsIgnoreCase("SubscriptionDiscount")).Value; if (string.IsNullOrEmpty(amount)) { return; } Decimal?subscriptionDiscount = Decimal.Parse(amount, CultureInfo.InvariantCulture); //return if subscription discount is zero if (subscriptionDiscount < 1) { return; } Decimal percent = subscriptionDiscount.Value / new Decimal(100); //BUSA-463 Subscription: Hold previous ActualPrice to calculate discount for this promotion orderLine.CostCode = orderLine.UnitNetPrice.ToString(CultureInfo.InvariantCulture); var num1 = NumberHelper.ApplyDiscount(UnitNetPrice, percent); //if (orderLine.PromotionResult != null) //{ // if (!(orderLine.UnitNetPrice < num1)) // { // CustomerOrderPromotion deleted = customerOrder.CustomerOrderPromotions.FirstOrDefault<CustomerOrderPromotion>((Func<CustomerOrderPromotion, bool>)(p => // { // Guid? orderLineId = p.OrderLineId; // Guid id = orderLine.Id; // if (!orderLineId.HasValue) // return false; // if (!orderLineId.HasValue) // return true; // return orderLineId.GetValueOrDefault() == id; // })); // if (deleted != null) // { // customerOrder.CustomerOrderPromotions.Remove(deleted); // this.UnitOfWork.GetRepository<CustomerOrderPromotion>().Delete(deleted); // } // } // else // return; //} //orderLine.PromotionResult = promotionResult; orderLine.UnitListPrice = productPriceDto.UnitListPrice; orderLine.UnitRegularPrice = productPriceDto.UnitRegularPrice; orderLine.UnitNetPrice = num1; orderLine.UnitNetPrice = orderLine.UnitNetPrice < Decimal.Zero ? Decimal.Zero : orderLine.UnitNetPrice; orderLine.TotalRegularPrice = NumberHelper.RoundCurrency(orderLine.UnitListPrice * orderLine.QtyOrdered); orderLine.TotalNetPrice = NumberHelper.RoundCurrency(orderLine.UnitNetPrice * orderLine.QtyOrdered); this.AddOrUpdateCustomerOrderPromotion(customerOrder, appliedPromotion, orderLine, promotionResult); } } } }