Esempio n. 1
0
        public void GetItemsReport(WalmartApi api)
        {
            var reportPath = api.GetItemsReport(AppSettings.WalmartReportBaseDirectory);
            var report     = new WalmartReport(reportPath);
            var items      = report.GetItems();

            _log.Info("Items count: " + items.Count);
            _log.Info("Report: " + reportPath);
        }
Esempio n. 2
0
        public void GetApsentItemsFromReport(WalmartApi api)
        {
            var reportPath = api.GetItemsReport(AppSettings.WalmartReportBaseDirectory);
            var report     = new WalmartReport(reportPath);
            var items      = report.GetItems();

            _log.Info("Items count: " + items.Count);
            _log.Info("Report: " + reportPath);

            using (var db = _dbFactory.GetRWDb())
            {
                var existListings = db.Listings.GetAll().Where(l => l.Market == (int)MarketType.Walmart).ToList();
                foreach (var item in items)
                {
                    var existListing = existListings.FirstOrDefault(l => l.SKU == item.SKU);
                    if (existListing == null)
                    {
                        _log.Info("SKU=" + item.SKU + ", Qty=" + item.AmazonRealQuantity);
                    }
                }
            }
        }
        public void RetireNotExistListings(string overrideReportPath)
        {
            IList <ItemDTO> items = new List <ItemDTO>();

            if (_api.Market == MarketType.Walmart)
            {
                var reportFilename = _api.GetItemsReport(_reportBaseDirectory);
                var report         = new WalmartReport(reportFilename);
                items = report.GetItems();
            }
            if (_api.Market == MarketType.WalmartCA)
            {
                var reportFilename = Path.Combine(_reportBaseDirectory, "item\\item_ca_report (8).zip");
                if (!String.IsNullOrEmpty(overrideReportPath))
                {
                    reportFilename = overrideReportPath;
                }

                var report = new WalmartReport(reportFilename);
                items = report.GetItems();
                foreach (var item in items)
                {
                    var itemId = item.SourceMarketId;
                    item.SourceMarketId = item.ListingId;
                    item.ListingId      = itemId;
                }
            }

            _log.Info("Received, item count=" + items.Count);

            var notExistItems = new List <ItemDTO>();

            using (var db = _dbFactory.GetRWDb())
            {
                var allExistSKUs = db.Listings.GetAll()
                                   .Where(i => !i.IsRemoved &&
                                          i.Market == (int)_api.Market &&
                                          (i.MarketplaceId == _api.MarketplaceId ||
                                           String.IsNullOrEmpty(_api.MarketplaceId)))
                                   .Select(i => new ItemDTO()
                {
                    SKU = i.SKU,
                })
                                   .ToList();
                allExistSKUs.ForEach(i => i.SKU = (i.SKU ?? "").ToUpper());

                foreach (var item in items)
                {
                    var upperSKU = (item.SKU ?? "").ToUpper();
                    var existSKU = allExistSKUs.FirstOrDefault(i => i.SKU == upperSKU);

                    if (existSKU == null)
                    {
                        _log.Info("Item market, sku=" + item.SKU + ", qty=" + item.AmazonRealQuantity + ", price=" + item.AmazonCurrentPrice + ", status=" + item.PublishedStatus);
                        notExistItems.Add(item);
                    }
                }

                var itemsToUpdate = notExistItems.ToList();
                itemsToUpdate.ForEach(i => i.RealQuantity = 0);

                _api.SubmitInventoryFeed("not_exist_reset_qty_" + DateTime.Now.Ticks.ToString(),
                                         itemsToUpdate,
                                         _feedBaseDirectory);

                foreach (var item in notExistItems)
                {
                    try
                    {
                        var result = _api.RetireItem(item.SKU);
                        if (result.IsFail)
                        {
                            _log.Info("Unable to retire SKU=" + item.SKU);
                        }
                    }
                    catch (Exception ex)
                    {
                        _log.Error(ex.Message, ex);
                    }
                }
            }
        }
        public void UpdateListingInfo(string overrideReportPath)
        {
            IList <ItemDTO> items = new List <ItemDTO>();

            if (_api.Market == MarketType.Walmart)
            {
                var reportFilename = _api.GetItemsReport(_reportBaseDirectory);
                var report         = new WalmartReport(reportFilename);
                items = report.GetItems();
            }
            if (_api.Market == MarketType.WalmartCA)
            {
                //https://seller.walmart.ca/resource/item/download?type=item
                var reportFilename = "";
                if (!String.IsNullOrEmpty(overrideReportPath))
                {
                    reportFilename = overrideReportPath;
                }
                else
                {
                    reportFilename = Path.Combine(_reportBaseDirectory, "item\\item_ca_report (10).zip");
                }

                var report = new WalmartReport(reportFilename);
                items = report.GetItems();
                foreach (var item in items)
                {
                    var itemId = item.SourceMarketId;
                    item.SourceMarketId = item.ListingId;
                    item.ListingId      = itemId;
                }
                //items = _api.GetAllItems();
            }


            _log.Info("Received, item count=" + items.Count);

            using (var db = _dbFactory.GetRWDb())
            {
                foreach (var item in items)
                {
                    var dbListing = db.Listings.GetAll()
                                    .OrderBy(l => l.IsRemoved)
                                    .FirstOrDefault(i => i.SKU == item.SKU &&
                                                    i.Market == (int)_api.Market);
                    if (dbListing != null)
                    {
                        //_log.Info("Item market, sku=" + item.SKU + ", qty=" + item.AmazonRealQuantity + ", price=" + item.AmazonRealQuantity + ", status=" + item.PublishedStatus);
                        if (dbListing.AmazonCurrentPrice != item.AmazonCurrentPrice)
                        {
                            _log.Info("SKU=" + item.SKU + ", price: " + dbListing.AmazonCurrentPrice + "=>" + item.AmazonCurrentPrice);
                        }
                        dbListing.AmazonCurrentPrice           = item.AmazonCurrentPrice;
                        dbListing.AmazonCurrentPriceUpdateDate = _time.GetAppNowTime();
                        dbListing.ListingId = StringHelper.GetFirstNotEmpty(item.ListingId, item.SKU);

                        if (dbListing.AmazonRealQuantity != item.AmazonRealQuantity)
                        {
                            _log.Info("SKU=" + item.SKU + ", qty: " + dbListing.AmazonRealQuantity + "=>" + item.AmazonRealQuantity);
                        }
                        dbListing.AmazonRealQuantity           = item.AmazonRealQuantity;
                        dbListing.AmazonRealQuantityUpdateDate = _time.GetAppNowTime();

                        //NOTE 25/11/2020: We do it in ReadInventoryInfo by separate API, this information is not valid
                        //if (dbListing.IsFBA != item.IsFBA)
                        //{
                        //    SystemActionHelper.RequestPriceRecalculation(db, _actionService, dbListing.Id, null);
                        //    _log.Info("SKU=" + item.SKU + ", isFBA: " + dbListing.IsFBA + "=>" + item.IsFBA);
                        //}
                        //dbListing.IsFBA = item.IsFBA;

                        var dbItem = db.Items.GetAll().FirstOrDefault(i => i.Id == dbListing.ItemId);
                        if (dbItem != null)
                        {
                            if (dbItem.Barcode != item.Barcode &&
                                !String.IsNullOrEmpty(item.Barcode))
                            {
                                _log.Info("Item Barcode has been updated, from=" + dbItem.Barcode + ", to=" + item.Barcode);
                                dbItem.Barcode = item.Barcode;
                            }

                            if (dbItem.SourceMarketId != item.SourceMarketId)
                            {
                                _log.Info("Item SourceMarketId has been updated, from=" + dbItem.SourceMarketId +
                                          ", to=" + item.SourceMarketId);
                                dbItem.SourceMarketId = item.SourceMarketId;
                            }

                            dbItem.Rank = item.Rank;

                            dbItem.ItemPublishedStatusReason = StringHelper.Substring(item.PublishedStatusReason, 255);

                            if (dbItem.ItemPublishedStatus == (int)PublishedStatuses.ChangesSubmited ||
                                dbItem.ItemPublishedStatus == (int)PublishedStatuses.Published ||
                                dbItem.ItemPublishedStatus == (int)PublishedStatuses.PublishedInactive ||
                                dbItem.ItemPublishedStatus == (int)PublishedStatuses.PublishedInProgress ||
                                dbItem.ItemPublishedStatus == (int)PublishedStatuses.PublishingErrors
                                //|| dbItem.ItemPublishedStatus == (int)PublishedStatuses.Unpublished //NOTE: always keep UNPUBLISHED status
                                )
                            {
                                if (dbItem.ItemPublishedStatus != item.PublishedStatus)
                                {
                                    _log.Info("Item update published status, from=" + dbItem.ItemPublishedStatus +
                                              ", to=" + item.PublishedStatus);
                                    dbItem.ItemPublishedStatus     = item.PublishedStatus;
                                    dbItem.ItemPublishedStatusDate = _time.GetAppNowTime();
                                }
                            }
                        }
                    }
                }
                db.Commit();
            }
        }
        public void FindSecondDayFlagDisparity(string overrideFeedpath)
        {
            IList <ItemDTO> items = new List <ItemDTO>();

            if (_api.Market == MarketType.Walmart)
            {
                string reportFilename = null;
                if (!String.IsNullOrEmpty(overrideFeedpath))
                {
                    reportFilename = overrideFeedpath;
                }
                else
                {
                    reportFilename = _api.GetItemsReport(_reportBaseDirectory);
                }
                var report = new WalmartReport(reportFilename);
                items = report.GetItems();
            }
            if (_api.Market == MarketType.WalmartCA)
            {
                string reportFilename = overrideFeedpath;

                var report = new WalmartReport(reportFilename);
                items = report.GetItems();
                foreach (var item in items)
                {
                    var itemId = item.SourceMarketId;
                    item.SourceMarketId = item.ListingId;
                    item.ListingId      = itemId;
                }
            }

            _log.Info("Received, item count=" + items.Count);

            var itemsIdToUpdate = new List <long>();

            using (var db = _dbFactory.GetRWDb())
            {
                var allExistSKUs = db.Listings.GetAll()
                                   .Where(i => !i.IsRemoved &&
                                          i.Market == (int)_api.Market &&
                                          (i.MarketplaceId == _api.MarketplaceId ||
                                           String.IsNullOrEmpty(_api.MarketplaceId)))
                                   .Select(i => new ItemDTO()
                {
                    SKU     = i.SKU,
                    IsPrime = i.IsPrime,
                    Id      = i.ItemId
                })
                                   .ToList();
                allExistSKUs.ForEach(i => i.SKU = (i.SKU ?? "").ToUpper());

                foreach (var item in items)
                {
                    var upperSKU = (item.SKU ?? "").ToUpper();
                    var existSKU = allExistSKUs.FirstOrDefault(i => i.SKU == upperSKU);

                    if (existSKU != null && existSKU.IsPrime != item.IsPrime)
                    {
                        itemsIdToUpdate.Add(existSKU.Id);
                    }
                }

                _log.Info("Items count with disparity: " + itemsIdToUpdate.Count);
                _log.Info("SKUs: " + String.Join(",", itemsIdToUpdate));
            }
        }