private Dictionary <ILineItem, List <ValidationIssue> > ValidatePurchaseOrder(IPurchaseOrder purchaseOrder) { var validationIssues = new Dictionary <ILineItem, List <ValidationIssue> >(); purchaseOrder.UpdatePlacedPriceOrRemoveLineItems(_customerContext.GetContactById(purchaseOrder.CustomerId), (item, issue) => validationIssues.AddValidationIssues(item, issue), _placedPriceProcessor); purchaseOrder.UpdateInventoryOrRemoveLineItems((item, issue) => validationIssues.AddValidationIssues(item, issue)); purchaseOrder.AdjustInventoryOrRemoveLineItems((item, issue) => validationIssues.AddValidationIssues(item, issue)); purchaseOrder.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings()); return(validationIssues); }
public virtual OmniumOrderForm MapOrderForm(IPurchaseOrder orderGroup, IOrderForm orderForm, IShipment[] shipments) { var market = _marketService.GetMarket(orderGroup.MarketId); var currency = orderGroup.Currency; var shipment = shipments.First(); var appliedDiscounts = orderGroup.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings())?.ToList(); var shippingDiscounts = appliedDiscounts?.Where(x => x.IsOfType(DiscountType.Shipping)); var discounts = appliedDiscounts?.Where(x => !x.IsOfType(DiscountType.Shipping)); var omniumDiscounts = MapDiscounts(discounts, orderGroup.Currency, market, shipment.ShippingAddress); var omniumShipments = shipments .Select(x => MapShipment(x, market, currency, shippingDiscounts)) .ToList(); var totals = GetOrderFormTotals(orderGroup, market, currency, omniumShipments); return(new OmniumOrderForm { Discounts = omniumDiscounts, Shipments = omniumShipments, Payments = orderForm.Payments.Select(x => MapPayment(x, totals.Total)).ToList(), LineItems = omniumShipments.SelectMany(x => x.LineItems).ToList(), Properties = orderForm.ToPropertyList(), HandlingTotal = totals.Handling, SubTotal = totals.SubTotal, SubTotalExclTax = totals.SubTotalExclTax, ShippingSubTotal = totals.Shipping, DiscountAmount = totals.OrderDiscounts, Total = totals.Total, TaxTotal = totals.TaxTotal, TotalExclTax = totals.TotalExclTax, AuthorizedPaymentTotal = Math.Min(orderForm.AuthorizedPaymentTotal, totals.Total), CapturedPaymentTotal = Math.Min(orderForm.CapturedPaymentTotal, totals.Total), ShippingDiscountTotal = totals.ShippingDiscounts }); }