public override void OnNotify(string notification, NotificationArgs args) { if (Global.IsIntegrationActive && Connector.IsWebServiceConnectionAvailable()) { //Used to load the cart and apply the discount after the user logged-in and has not empty cart var myArgs = (Dynamicweb.Notifications.Standard.User.OnExtranetLoginArgs)args; var order = Dynamicweb.Ecommerce.Common.Context.Cart; if (myArgs.User != null) { UrlHandler.Instance.ClearCachedUrl(); Dynamicweb.Ecommerce.Integration.ErpResponseCache.ClearAllCaches(); PrepareProductInfoProvider.ClearUserCache(); //check if user has updates CheckUser(myArgs.User); } if (order != null && order.IsCart && EnabledAndActive()) { if (Global.EnableCartCommunication(order.Complete)) { OrderHandler.UpdateOrder(order, LiveIntegrationSubmitType.LiveOrderOrCart); } else { CheckOrderPrices(order, "OnExtranetLogin"); } } } }
private static void SetProductsInfo(List <Product> products, User user = null) { if (!PrepareProductInfoProvider.FetchProductInfos(products, user)) { return; } // Set values foreach (Product product in products) { PrepareProductInfoProvider.FillProductValues(product); } }
/// <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); } }
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); }