protected override DocumentInfo ComposeDocument(IUnitOfWork db, long companyId, MarketType market, string marketplaceId, IList <string> asinList) { Dictionary <string, int> _quantityToSend = new Dictionary <string, int>(); Log.Info("Get listings for quantity update"); var requestInfoes = db.SystemActions.GetAllAsDto() .Where(a => a.Type == (int)SystemActionType.UpdateOnMarketProductQuantity && a.Status != (int)SystemActionStatus.Done) .ToList(); var requestedSKUs = requestInfoes.Select(i => i.Tag).ToList(); var dtoItems = (from i in db.Items.GetAllViewAsDto() where requestedSKUs.Contains(i.SKU) && i.PublishedStatus == (int)PublishedStatuses.Published && i.Market == (int)market && (String.IsNullOrEmpty(marketplaceId) || i.MarketplaceId == marketplaceId) select i).ToList(); foreach (var dtoItem in dtoItems) { var requestInfo = requestInfoes.FirstOrDefault(i => i.Tag == dtoItem.SKU); var info = SystemActionHelper.FromStr <UpdateQtyInput>(requestInfo.InputData); dtoItem.Id = (int)(requestInfo?.Id ?? 0); dtoItem.RealQuantity = info.NewQty; } _quantityToSend = new Dictionary <string, int>(); if (dtoItems.Any()) { var quantMessages = new List <XmlElement>(); var index = 0; foreach (var listing in dtoItems) { //Skip processing duplicate SKU if (_quantityToSend.ContainsKey(listing.SKU)) { continue; } index++; var quantity = listing.RealQuantity; Log.Info("add listing " + index + ", listingId=" + listing.Id + ", SKU=" + listing.SKU + ", quantity=" + quantity); quantMessages.Add(FeedHelper.ComposeInventoryMessage(index, listing.SKU, quantity, null, _fulfillmentLatency)); _quantityToSend.Add(listing.SKU, quantity); } Log.Info("Compose feed"); var merchant = db.Companies.Get(companyId).AmazonFeedMerchantIdentifier; var document = FeedHelper.ComposeFeed(quantMessages, merchant, Type.ToString()); return(new DocumentInfo { XmlDocument = document, NodesCount = index }); } return(null); }
protected override DocumentInfo ComposeDocument(IUnitOfWork db, long companyId, MarketType market, string marketplaceId, IList <string> asinList) { Log.Info("Get listings for quantity update"); if (asinList == null || !asinList.Any()) { Listings = db.Listings.GetQuantityUpdateRequiredList(market, marketplaceId); } else { Listings = db.Listings.GetAll().Where(l => asinList.Contains(l.SKU) && l.Market == (int)market && (l.MarketplaceId == marketplaceId || String.IsNullOrEmpty(marketplaceId))) .ToList(); } _quantityToSend = new Dictionary <string, int>(); if (Listings.Any()) { var quantMessages = new List <XmlElement>(); var index = 0; foreach (var listing in Listings) { //Skip processing duplicate SKU if (_quantityToSend.ContainsKey(listing.SKU)) { continue; } index++; //NOTE: Case when we have 2 duplicate listings with different styleId (in case when manufacturer change StyleId) var realQuantity = Listings.Where(l => l.SKU == listing.SKU).Sum(l => l.RealQuantity); var quantity = listing.DisplayQuantity.HasValue ? Math.Min(listing.DisplayQuantity.Value, realQuantity) : listing.RealQuantity; //NOTE: 101 qty rule if (quantity >= 30) { quantity = 101; } Log.Info("add listing " + index + ", listingId=" + listing.Id + ", SKU=" + listing.SKU + ", quantity=" + quantity + " (display=" + listing.DisplayQuantity + ", real=" + realQuantity + "(" + listing.RealQuantity + ")" + ")" + " , restockDate=" + listing.RestockDate); quantMessages.Add(FeedHelper.ComposeInventoryMessage(index, listing.SKU, quantity, listing.RestockDate, _fulfillmentLatency)); listing.MessageIdentifier = index; _quantityToSend.Add(listing.SKU, quantity); } Log.Info("Compose feed"); var merchant = db.Companies.Get(companyId).AmazonFeedMerchantIdentifier; var document = FeedHelper.ComposeFeed(quantMessages, merchant, Type.ToString()); return(new DocumentInfo { XmlDocument = document, NodesCount = index }); } return(null); }