protected void UpdateFeedStatus(IUnitOfWork db, FeedDTO currentFeed, IList <WalmartFeedItemDTO> feedItems, TimeSpan waitTimeOfProcessing) { var thresholdDate = waitTimeOfProcessing == TimeSpan.Zero ? _time.GetAppNowTime().AddHours(-8) : _time.GetAppNowTime().Subtract(waitTimeOfProcessing); _log.Info("thresholdDate=" + thresholdDate); if (feedItems.All(i => WalmartUtils.ConvertFromFeedItemPublishedStatusToStandard(i.Status) != PublishedStatuses.PublishedInProgress) || currentFeed.SubmitDate < thresholdDate) { var feed = db.Feeds.GetAll().FirstOrDefault(f => f.Id == currentFeed.Id); if (feed != null) { feed.Status = (int)FeedStatus.Processed; db.Commit(); currentFeed.Status = (int)FeedStatus.Processed; _log.Info(String.Format("Mark feed, id={0}, marketId={1}, as processed", feed.Id, feed.AmazonIdentifier)); } } }
protected override void ProcessFeedItem(IUnitOfWork db, WalmartFeedItemDTO feedItem, DateTime feedSubmitDate) { var status = WalmartUtils.ConvertFromFeedItemPublishedStatusToStandard(feedItem.Status); var dbListing = db.Listings.GetAll().FirstOrDefault(l => l.SKU == feedItem.ItemId && l.Market == (int)_api.Market); if (dbListing != null && status == PublishedStatuses.Published) { dbListing.PriceUpdateRequested = false; _log.Info("Status has been updated"); } }
protected override void ProcessFeedItem(IUnitOfWork db, WalmartFeedItemDTO feedItem, DateTime feedSubmitDate) { var status = WalmartUtils.ConvertFromFeedItemPublishedStatusToStandard(feedItem.Status); var dbListing = db.Listings.GetAll().FirstOrDefault(l => l.SKU == feedItem.ItemId && l.Market == (int)_api.Market && !l.IsRemoved); feedItem.Errors = feedItem.Errors ?? new List <ItemErrorDTO>(); if (dbListing != null) { var dbItem = db.Items.GetAll().FirstOrDefault(i => i.Id == dbListing.ItemId); if (dbItem != null) { _log.Info("Status has been updated"); var dbItemAdditions = db.ItemAdditions .GetAll() .Where(ia => ia.ItemId == dbItem.Id && ia.Field == ItemAdditionFields.PublishError) .ToList(); if (dbItemAdditions.Count > 0 && !feedItem.Errors.Any()) { foreach (var dbItemAddition in dbItemAdditions) { db.ItemAdditions.Remove(dbItemAddition); } } else { if (dbItemAdditions.Count == 0 && feedItem.Errors.Any()) { foreach (var feedError in feedItem.Errors) { db.ItemAdditions.Add(new Core.Entities.Listings.ItemAddition() { CreateDate = _time.GetAmazonNowTime(), Field = ItemAdditionFields.PublishError, ItemId = dbItem.Id, Value = feedError.Message + ", Code: " + feedError.Code + ", Type: " + feedError.Type, Source = feedItem.FeedId.ToString() }); } } else { if (dbItemAdditions.Count == feedItem.Errors.Count) { for (var i = 0; i < dbItemAdditions.Count; i++) { dbItemAdditions[i].CreateDate = _time.GetAmazonNowTime(); dbItemAdditions[i].Value = feedItem.Errors[i].Message + ", Code: " + feedItem.Errors[i].Code + ", Type: " + feedItem.Errors[i].Type; dbItemAdditions[i].Source = feedItem.FeedId.ToString(); } } else { foreach (var dbItemError in dbItemAdditions) { db.ItemAdditions.Remove(dbItemError); } foreach (var feedError in feedItem.Errors) { db.ItemAdditions.Add(new Core.Entities.Listings.ItemAddition() { CreateDate = _time.GetAppNowTime(), Field = ItemAdditionFields.PublishError, ItemId = dbItem.Id, Value = feedError.Message + ", Code: " + feedError.Code + ", Type: " + feedError.Type, Source = feedItem.FeedId.ToString() }); } } } } if (dbItem.ItemPublishedStatusDate < feedSubmitDate.AddMinutes(15)) //NOTE: update status when if they was updated before submittion { dbItem.ItemPublishedStatus = (int)status; dbItem.ItemPublishedStatusDate = _time.GetAppNowTime(); } } } }
public void ExportSetupByMatch() { using (var db = _dbFactory.GetRWDb()) { var allAmazonItems = db.Items.GetAllViewActual() .Where(i => i.Market == (int)MarketType.Amazon && i.MarketplaceId == MarketplaceKeeper.AmazonComMarketplaceId) .Select(i => new ItemDTO() { SKU = i.SKU, Barcode = i.Barcode, CurrentPrice = i.CurrentPrice, StyleId = i.StyleId, }) .ToList(); var allWalmartItems = db.Items.GetAllViewActual() .Where(i => i.Market == (int)MarketType.Walmart) .Select(i => new ItemDTO() { SKU = i.SKU, Barcode = i.Barcode }) .ToList(); var results = new List <SetupByMatchProduct>(allAmazonItems.Count); foreach (var amzItem in allAmazonItems) { var genderValue = amzItem.StyleId.HasValue ? db.StyleFeatureValues.GetFeatureValueByStyleIdByFeatureId(amzItem.StyleId.Value, StyleFeatureHelper.GENDER)?.Value : null; if (allWalmartItems.All(i => i.Barcode != amzItem.Barcode)) { var sku = amzItem.SKU; var index = 0; while (allWalmartItems.Any(i => i.SKU == sku)) { sku = SkuHelper.SetSKUMiddleIndex(sku, index); index++; } results.Add(new SetupByMatchProduct() { ProductIdType1 = "UPC", ProductId1 = amzItem.Barcode, ProductTaxCode = WalmartUtils.GetProductTaxCode(genderValue, null)?.ToString(), SKU = sku, Currency = "USD", Price = amzItem.CurrentPrice, Weight = PriceHelper.RoundToTwoPrecision((decimal)((amzItem.Weight == null || amzItem.Weight == 0) ? 5 : amzItem.Weight.Value) / (decimal)16), WeightUnit = "lb", Category = "Clothing", SubCategory = "Clothing" }); } } var b = new ExportColumnBuilder <SetupByMatchProduct>(); var columns = new List <ExcelColumnInfo>() { b.Build(p => p.ProductIdType1, "Product Identifier-Product Id Type (#1) *", 15), b.Build(p => p.ProductId1, "Product Identifier-Product Id (#1) *", 15), b.Build(p => p.ProductTaxCode, "Product Tax Code *", 15), b.Build(p => p.ProductIdType2, "Additional Product Attribute-Product Attribute Name (#1) (Optional)", 15), b.Build(p => p.ProductId2, "Additional Product Attribute-Product Attribute Value (#1) (Optional)", 15), b.Build(p => p.SKU, "Sku *", 15), b.Build(p => p.ASIN, "ASIN (Optional)", 15), b.Build(p => p.Currency, "Price-Currency *", 15), b.Build(p => p.Price, "Price-Amount *", 15), b.Build(p => p.Weight, "Shipping Weight-Value *", 15), b.Build(p => p.WeightUnit, "Shipping Weight-Unit *", 15), b.Build(p => p.Category, "Category *", 15), b.Build(p => p.SubCategory, "Sub-category *", 15), }; var outputFilepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "WMSetupByMatch-" + DateTime.Now.ToString("yyyyddMMHHmmss") + ".xls"); using (var stream = ExcelHelper.Export(results, columns, null)) { stream.Seek(0, SeekOrigin.Begin); using (var fileStream = File.Create(outputFilepath)) { stream.CopyTo(fileStream); } } } }