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); } }
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); }