protected void UpdateOrder(Dynamicweb.Ecommerce.Orders.Order order, string notification) { //todo: implement try catch if (order != null) { if (Global.EnableCartCommunication(order.Complete)) { OrderHandler.UpdateOrder(order, LiveIntegrationSubmitType.LiveOrderOrCart); } else { CheckOrderPrices(order, "Line.Decreased"); } } }
/// <summary> /// Clears and sets the product information in Dynamicweb for all the products in the order. /// </summary> /// <param name="order"></param> protected void SetProductInformation(Dynamicweb.Ecommerce.Orders.Order order) { if (order == null) { return; } // clear product cache to ensure refresh from ERP Dynamicweb.Ecommerce.Integration.ErpResponseCache.ClearAllCaches(); PrepareProductInfoProvider.ClearUserCache(); // read all products in the order var productsToUpdate = order.OrderLines.Where(ol => ol.IsProduct()).Select(ol => ol.Product); if (productsToUpdate != null && productsToUpdate.Any()) { Logging.Logger.Instance.Log(Logging.ErrorLevel.DebugInfo, string.Format("Reload prices. products #{0}", productsToUpdate.Count())); User orderUser = User.GetUserByID(order.CustomerAccessUserId); SetProductsInfo(productsToUpdate.ToList(), orderUser); } }
/// <summary> /// Updates product information on the order /// </summary> /// <param name="order">order to be have stock validated</param> public static void UpdateStockOnOrder(Dynamicweb.Ecommerce.Orders.Order order) { // call LI method to check stocks in ERP NotificationSubscribers.IntegrationBaseNotificationSubscriber.UpdateProductInformation(order); }
protected static void CheckOrderPrices(Dynamicweb.Ecommerce.Orders.Order order, string notification) { if (order == null || order.OrderLines.Count <= 0) { return; } uint productsCount = 0; //updatedProducts = 0, Dictionary <Product, double> products = new Dictionary <Product, double>(order.OrderLines.Count); //LogToFile.Log(string.Format("read ({0}) order id = {1} lines# = {2}", notification, order.ID, order.OrderLines.Count) // , global.LogFolder, LogToFile.LogType.ManyEntriesPerFile); foreach (var ol in order.OrderLines) { if (ol.IsProduct()) { ++productsCount; //LogToFile.Log(string.Format("read ({0}) product {1} line id = {2}", notification, ol.Product.ID, ol.ID) // , global.LogFolder, LogToFile.LogType.ManyEntriesPerFile); if (!products.ContainsKey(ol.Product)) { products.Add(ol.Product, ol.Quantity); } } } if (PrepareProductInfoProvider.FetchProductInfos(products.Keys.ToList())) { foreach (var p in products) { var product = p.Key; //LogToFile.Log(string.Format("update ({0}) product {1}", notification, p.ID) // , global.LogFolder, LogToFile.LogType.ManyEntriesPerFile); PrepareProductInfoProvider.FillProductValues(product, p.Value); var orderline = order.OrderLines.First(ol => ol.ProductId == product.Id); if (product.Price.PriceWithVAT == orderline.UnitPrice.PriceWithVAT && product.Price.PriceWithoutVAT == orderline.UnitPrice.PriceWithoutVAT) { if (orderline.Price.PriceWithVAT == orderline.Quantity * orderline.UnitPrice.PriceWithVAT && orderline.Price.PriceWithoutVAT == orderline.Quantity * orderline.UnitPrice.PriceWithoutVAT) { continue; } } //DEBUG //++updatedProducts; orderline.AllowOverridePrices = true; orderline.SetUnitPrice(product.Price, false); orderline.Type = Convert.ToString(Convert.ToInt32(Dynamicweb.Ecommerce.Orders.OrderLineType.Fixed)); orderline.Price.PriceWithVAT = orderline.Quantity * orderline.UnitPrice.PriceWithVAT; orderline.Price.PriceWithoutVAT = orderline.Quantity * orderline.UnitPrice.PriceWithoutVAT; } } order.ForcePriceRecalculation(); //LogToFile.Log(string.Format("finished ({0}) order id = {1} products# = {2} updated = {3}", notification, order.ID // , productsCount, updatedProducts), global.LogFolder, LogToFile.LogType.ManyEntriesPerFile); }
/// <summary> /// Method to update order in ERP. /// </summary> /// <param name="order">order to update in the ERP</param> /// <returns>null if no communication has made, or bool if order has updated or not</returns> public static bool?UpdateOrder(Dynamicweb.Ecommerce.Orders.Order order) { return(OrderHandler.UpdateOrder(order, LiveIntegrationSubmitType.FromTemplates)); }