private bool Filter(OrderFilter filter, IPurchaseOrder order) { var result = true; if (result && !string.IsNullOrEmpty(filter.OrderGroupId)) { result = order.OrderLink.OrderGroupId.ToString().Contains(filter.OrderGroupId); } if (result && !string.IsNullOrEmpty(filter.PurchaseOrderNumber)) { result = order.OrderNumber.Contains(filter.PurchaseOrderNumber); } if (result && filter.DateFrom.HasValue) { result = order.Created.Date >= filter.DateFrom.Value.Date; } if (result && filter.DateTo.HasValue) { result = order.Created.Date <= filter.DateTo.Value.Date; } if (result && !(filter.OrderStatusId == 0)) { result = order.OrderStatus.Id == filter.OrderStatusId; } if (result && filter.PriceFrom > 0) { result = order.GetTotal() >= filter.PriceFrom; } if (result && filter.PriceTo > 0) { result = order.GetTotal() <= filter.PriceTo; } if (result && !string.IsNullOrEmpty(filter.AddressId)) { result = order.GetFirstForm().Shipments.Where(x => x.ShippingAddress.Id == filter.AddressId).Count() > 0; } if (result && !string.IsNullOrEmpty(filter.PaymentMethodId)) { result = order.GetFirstForm().Payments.Where(x => x.PaymentMethodId.ToString() == filter.PaymentMethodId).Count() > 0; } if (result && !string.IsNullOrEmpty(filter.Keyword)) { result = order.GetAllLineItems().Where(x => x.DisplayName.Contains(filter.Keyword) || x.Code.Contains(filter.Keyword)).Count() > 0; } return(result); }
/// <summary> /// Updates display name with current language. /// </summary> /// <param name="purchaseOrder">The purchase order.</param> public static void UpdateDisplayNameWithCurrentLanguage(IPurchaseOrder purchaseOrder) { if (purchaseOrder != null) { foreach (ILineItem lineItem in purchaseOrder.GetAllLineItems()) { lineItem.DisplayName = GetDisplayNameOfCurrentLanguage(lineItem, 100); } } }
public ICart PlaceOrderToCart(IPurchaseOrder purchaseOrder, ICart cart) { ICart returnCart = cart; var lineItems = purchaseOrder.GetAllLineItems(); foreach (var lineItem in lineItems) { cart.AddLineItem(lineItem); lineItem.IsInventoryAllocated = false; } return(returnCart); }
/// <summary> /// Call OrderRest API /// </summary> /// <param name="order"></param> public void PostEvent(IPurchaseOrder order) { Logger.Information($"Order has been placed: {order.OrderNumber}"); //basic info var orderNumber = order.OrderNumber; var orderDate = order.Created; var customerName = order.Name; var currencyCode = order.Currency.CurrencyCode; var currency = new Mediachase.Commerce.Currency(currencyCode); var form = order.Forms.FirstOrDefault(); var subTotal = form.GetSubTotal(currency); var handlingTotal = form.GetHandlingTotal(currency); //var couponCodes = form.CouponCodes; //var formName = form.Name; //var payment = form.Payments.FirstOrDefault(); //shipment info var shipment = form.Shipments.FirstOrDefault(); var warehouseCode = shipment.WarehouseCode; var shipmentTrackingNumber = shipment.ShipmentTrackingNumber; var shippingMethodName = shipment.ShippingMethodName; var shipAdress = shipment.ShippingAddress; var city = shipAdress.City; var countryCode = shipAdress.CountryCode; var daytimePhoneNumber = shipAdress.DaytimePhoneNumber; var eveningPhoneName = shipAdress.EveningPhoneNumber; var email = shipAdress.Email; var line1 = shipAdress.Line1; var line2 = shipAdress.Line2; var organization = shipAdress.Organization; var regionCode = shipAdress.RegionCode; var regionName = shipAdress.RegionName; //lineItems var lineItems = order.GetAllLineItems().Select(lineItem => new { Code = lineItem.Code, DisplayName = lineItem.DisplayName, Quantity = lineItem.Quantity, PlacedPrice = lineItem.PlacedPrice, ThumbnailUrl = lineItem.GetThumbnailUrl(), DiscountedPrice = lineItem.GetDiscountedPrice(currency).ToString(), DiscountTotal = lineItem.GetDiscountTotal(currency).ToString(), OrderDiscountValue = lineItem.GetOrderDiscountValue(), FullUrl = lineItem.GetFullUrl(), ExtendedPrice = lineItem.GetExtendedPrice(currency).ToString() }).ToList(); string url = System.Web.Configuration.WebConfigurationManager.AppSettings.Get("EPi.OrderIntegration.Url"); string resource = System.Web.Configuration.WebConfigurationManager.AppSettings.Get("EPi.OrderIntegration.Resource"); string apiKey = System.Web.Configuration.WebConfigurationManager.AppSettings.Get("EPi.OrderIntegration.ApiKey"); if (string.IsNullOrEmpty(url)) { return; } RestClient restClient = new RestClient(url); RestRequest restRequest = new RestRequest(resource, Method.POST); //Specifies request content type as Json restRequest.RequestFormat = DataFormat.Json; //Create a body with specifies parameters as json restRequest.AddJsonBody(new { OrderInfo = new { OrderNumber = orderNumber, CurrencyCode = currencyCode, CustomerName = customerName, WarehouseCode = warehouseCode, HandlingTotal = handlingTotal.ToString(), OrderDate = orderDate, SubTotal = subTotal.ToString() }, Shipment = new { City = city, CountryCode = currencyCode, EveningPhoneNumber = eveningPhoneName, DaytimePhoneNumber = daytimePhoneNumber, RegionCode = regionCode, RegionName = regionName, Email = email, Line1 = line1, Line2 = line2, ShipmentTrackingNumber = shipmentTrackingNumber, ShippingMethodName = shippingMethodName }, LineItems = lineItems }); IRestResponse restResponse = null; try { restResponse = restClient.Execute(restRequest); } catch (Exception ex) { Logger.Debug(" REST API Error Message : " + ex.Message); if (ex.InnerException != null) { Logger.Debug(" REST API Inner Exception : " + ex.InnerException.Message); } } finally { if (restResponse != null) { Logger.Debug(" REST API response content : " + restResponse.Content); } } }