//add item to container with specific categoryid private void addItemToContainer(AddItemRequestContainerTypeCollection itemsContainers,string categoryID) { AddItemRequestContainerType itemContainer = new AddItemRequestContainerType(); ItemType item = ItemHelper.BuildItem(); item.PrimaryCategory.CategoryID=categoryID; itemContainer.Item=item; itemContainer.MessageID=Convert.ToString(itemsContainers.Count+1); itemsContainers.Add(itemContainer); }
//add item to container with specific categoryid private void addItemToContainer(AddItemRequestContainerTypeCollection itemsContainers, string categoryID) { AddItemRequestContainerType itemContainer = new AddItemRequestContainerType(); ItemType item = ItemHelper.BuildItem(); item.PrimaryCategory.CategoryID = categoryID; itemContainer.Item = item; itemContainer.MessageID = Convert.ToString(itemsContainers.Count + 1); itemsContainers.Add(itemContainer); }
public void SubmitProductsListingFeed(List <MarketplaceProductFeedDto> productFeeds, string submittedBy) { // take out the products which has no information for eBay var invalidProducts = productFeeds .Where(x => x.IsBlacklisted || x.eBayProductFeed == null || x.eBayProductFeed.CategoryId == null) .ToList(); if (invalidProducts.Any()) { _logger.LogWarning(LogEntryType.eBayProductListing, string.Format("{0}/{1} EIS products which will not be included to eBay product listing feed due to no eBay category id or no eBay information or blacklisted.", invalidProducts.Count, productFeeds.Count)); productFeeds.RemoveAll(x => x.IsBlacklisted || x.eBayProductFeed == null || x.eBayProductFeed.CategoryId == null); } // let's do not include the eBay products which have already item id var alreadyAddedProducts = productFeeds .Where(x => !string.IsNullOrEmpty(x.eBayProductFeed.ItemId)) .ToList(); if (alreadyAddedProducts.Any()) { _logger.LogWarning(LogEntryType.eBayProductListing, string.Format("{0}/{1} EIS products which will not be included to eBay product listing feed since they are already added. Please do the product revise feed instead!", alreadyAddedProducts.Count, productFeeds.Count)); productFeeds.RemoveAll(x => !string.IsNullOrEmpty(x.eBayProductFeed.ItemId)); } // determine if there's product feed to post if (!productFeeds.Any()) { _logger.LogWarning(LogEntryType.eBayProductListing, "No eBay products for product listing."); return; } // set the log file name _context.ApiLogManager.ApiLoggerList.Add(new FileLogger(string.Format(_logDirectory, MethodBase.GetCurrentMethod().Name), false, true, true)); var totalBatches = Math.Ceiling(productFeeds.Count / 5.0); var failedBatches = new List <MarketplaceProductFeedDto>(); for (var i = 0; i < totalBatches; i++) { // send the product listing feed by 5 items as required for eBay Trading API var batchedProducts = productFeeds.Skip(i * 5).Take(5).ToList(); var itemRequestList = new List <AddItemRequestContainerType>(); try { foreach (var product in batchedProducts) { var itemRequest = new AddItemRequestContainerType(); // create the item request object for product itemRequest.Item = RequestHelper.CreateItemType(product, _credential.eBayDescriptionTemplate); itemRequest.MessageID = product.EisSKU; itemRequestList.Add(itemRequest); } // add it to the item collection object var apiCall = new AddItemsCall(_context); var response = apiCall.AddItems(new AddItemRequestContainerTypeCollection(itemRequestList.ToArray())); // parse the product's item id and fees from response object var itemContainers = getParsedResponseItemContainers(response.ToArray()); // update the product eBay ItemId and log the posting fees logAndUpdateProductItemId(itemContainers, LogEntryType.eBayProductListing); } catch (Exception ex) { // add it to the faulty list failedBatches.AddRange(batchedProducts); var description = string.Format("Batch: {0}/{1} - Error in submitting PRODUCT_LISTING feed. \nError Message: {2} \nRequested by: {3}", i + 1, totalBatches, EisHelper.GetExceptionMessage(ex), submittedBy); _logger.LogError(LogEntryType.eBayProductListing, description, ex.StackTrace); } } // resend the faulty product listing feed if there's any if (failedBatches.Any()) { _logger.LogInfo(LogEntryType.eBayProductListing, string.Format("Starting sending PRODUCT_LISTING feed for failed batches. Count: {0}", failedBatches.Count)); // iterate and send each item foreach (var item in failedBatches) { SubmitSingleProductListingFeed(item, submittedBy); } _logger.LogInfo(LogEntryType.eBayProductListing, string.Format("Resubmission for {0} failed items for PRODUCT_LISTING feed has been completed.", failedBatches.Count())); } else { _logger.LogInfo(LogEntryType.eBayProductListing, string.Format("Successfully posted product listing feed for {0} - {1} product items. \nRequested by: {2}", ChannelName, productFeeds.Count, submittedBy)); } }