Ejemplo n.º 1
0
        public void SubmitTestPriceFeed(WalmartCAApi api)
        {
            var item1 = new ItemDTO()
            {
                StyleId      = 1158,
                SKU          = "21TE062ERDZA-1-3T", // "21TE062ERDZA-1-3T",
                CurrentPrice = 19.89M
            };

            using (var db = _dbFactory.GetRWDb())
            {
                if (item1.StyleId.HasValue)
                {
                    var itemStyle = db.StyleFeatureValues.GetFeatureValueByStyleIdByFeatureId(
                        item1.StyleId.Value,
                        StyleFeatureHelper.ITEMSTYLE);

                    if (!item1.ListPrice.HasValue && itemStyle != null)
                    {
                        item1.ListPrice = PriceHelper.GetDefaultMSRP(itemStyle.Value);
                    }
                }
            }

            //var result = api.GetFeed("20F17E0B509143B89023AD9B8036D158@AQYBAQA");
            //_log.Info(result.ToString());

            //var result = api.SendPrice(item1);
            //_log.Info(result.ToString());

            api.SubmitPriceFeed("1", new List <ItemDTO>()
            {
                item1
            }, AppSettings.WalmartFeedBaseDirectory);
        }
Ejemplo n.º 2
0
        public void SendPriceUpdates()
        {
            _log.Info("Begin PriceUpdates");
            var today      = _time.GetAppNowTime().Date;
            var beforeDate = _time.GetAppNowTime().AddMinutes(-180); //NOTE: update not often, every 3 hours

            using (var db = _dbFactory.GetRWDb())
            {
                var itemQuery = from l in db.Listings.GetAll()
                                join i in db.Items.GetAll() on l.ItemId equals i.Id
                                join s in db.Styles.GetAll() on i.StyleId equals s.Id
                                join sale in db.StyleItemSaleToListings.GetAllListingSaleAsDTO() on l.Id equals sale.ListingId into withSale
                                from sale in withSale.DefaultIfEmpty()
                                where l.PriceUpdateRequested &&
                                (i.ItemPublishedStatus == (int)PublishedStatuses.Published ||
                                 i.ItemPublishedStatus == (int)PublishedStatuses.HasChanges) &&
                                (!l.LastPriceUpdatedOnMarket.HasValue || l.LastPriceUpdatedOnMarket < beforeDate) &&
                                i.Market == (int)_api.Market &&
                                !l.IsRemoved
                                select new ItemDTO()
                {
                    ListingEntityId = l.Id,
                    SKU             = l.SKU,
                    StyleId         = i.StyleId,
                    CurrentPrice    = l.CurrentPrice,
                    ListPrice       = s.MSRP,
                    SalePrice       = sale != null && sale.SaleStartDate <= today ? sale.SalePrice : null,
                };

                var items = itemQuery.ToList();

                if (items.Any())
                {
                    _log.Info("Listings to sync=" + String.Join(", ", items.Select(i => i.SKU).ToList()));

                    foreach (var item in items)
                    {
                        var dbListing = db.Listings.GetAll().FirstOrDefault(i => i.Id == item.ListingEntityId);

                        if (dbListing == null)
                        {
                            _log.Info("Item haven't listing, item=" + item.Id);
                            continue;
                        }

                        if (item.StyleId.HasValue)
                        {
                            var itemStyle = db.StyleFeatureValues.GetFeatureValueByStyleIdByFeatureId(
                                item.StyleId.Value,
                                StyleFeatureHelper.ITEMSTYLE);

                            if (!item.ListPrice.HasValue && itemStyle != null)
                            {
                                item.ListPrice = PriceHelper.GetDefaultMSRP(itemStyle.Value);
                            }
                        }

                        _log.Info(String.Format("Send SKU={0}, price={1}, msrp={2}, salePrice={3}",
                                                item.SKU,
                                                item.CurrentPrice,
                                                item.ListPrice,
                                                item.SalePrice));

                        var result = _api.SendPrice(item.SKU, item.SalePrice ?? item.CurrentPrice);
                        if (result.IsSuccess)
                        {
                            dbListing.PriceUpdateRequested = false;
                        }
                        else
                        {
                            _log.Info("Can't update price");
                        }
                        dbListing.LastPriceUpdatedOnMarket = _time.GetAppNowTime();
                        db.Commit();
                    }
                }
                _log.Info("End PriceUpdates");
            }
        }
Ejemplo n.º 3
0
        public void SubmitFeed(IList <string> skuList)
        {
            var today = _time.GetAppNowTime().Date;

            using (var db = _dbFactory.GetRWDb())
            {
                IList <ItemDTO> dtoListings;

                if (skuList == null || !skuList.Any())
                {
                    var listingQuery = from l in db.Listings.GetAll()
                                       join i in db.Items.GetAll() on l.ItemId equals i.Id
                                       join s in db.Styles.GetAll() on i.StyleId equals s.Id
                                       join sale in db.StyleItemSaleToListings.GetAllListingSaleAsDTO() on l.Id equals sale.ListingId
                                       into withSale
                                       from sale in withSale.DefaultIfEmpty()
                                       where l.PriceUpdateRequested &&
                                       (i.ItemPublishedStatus != (int)PublishedStatuses.New ||
                                        i.ItemPublishedStatus != (int)PublishedStatuses.None ||
                                        i.ItemPublishedStatus != (int)PublishedStatuses.PublishingErrors) &&
                                       i.Market == (int)Market &&
                                       !l.IsRemoved
                                       select new ItemDTO()
                    {
                        ListingEntityId = l.Id,
                        SKU             = l.SKU,
                        StyleId         = i.StyleId,
                        CurrentPrice    = l.CurrentPrice,
                        ListPrice       = s.MSRP,
                        SalePrice       = sale != null && sale.SaleStartDate <= today ? sale.SalePrice : null,
                    };

                    dtoListings = listingQuery.ToList();
                }
                else
                {
                    var listingQuery = from l in db.Listings.GetAll()
                                       join i in db.Items.GetAll() on l.ItemId equals i.Id
                                       join s in db.Styles.GetAll() on i.StyleId equals s.Id
                                       join sale in db.StyleItemSaleToListings.GetAllListingSaleAsDTO() on l.Id equals sale.ListingId
                                       into withSale
                                       from sale in withSale.DefaultIfEmpty()
                                       where i.Market == (int)Market &&
                                       !l.IsRemoved &&
                                       skuList.Contains(l.SKU)
                                       select new ItemDTO()
                    {
                        ListingEntityId = l.Id,
                        SKU             = l.SKU,
                        StyleId         = i.StyleId,
                        CurrentPrice    = l.CurrentPrice,
                        ListPrice       = s.MSRP,
                        SalePrice       = sale != null && sale.SaleStartDate <= today ? sale.SalePrice : null,
                    };

                    dtoListings = listingQuery.ToList();
                }

                if (dtoListings.Any())
                {
                    _log.Info("Listings to submit=" + String.Join(", ", dtoListings.Select(i => i.SKU).ToList()));

                    var items = dtoListings.ToList();

                    foreach (var item in items)
                    {
                        if (item.StyleId.HasValue)
                        {
                            var itemStyle = db.StyleFeatureValues.GetFeatureValueByStyleIdByFeatureId(
                                item.StyleId.Value,
                                StyleFeatureHelper.ITEMSTYLE);

                            if (!item.ListPrice.HasValue && itemStyle != null)
                            {
                                item.ListPrice = PriceHelper.GetDefaultMSRP(itemStyle.Value);
                            }
                        }

                        _log.Info(String.Format("Send SKU={0}, price={1}, msrp={2}, salePrice={3}",
                                                item.SKU,
                                                item.CurrentPrice,
                                                item.ListPrice,
                                                item.SalePrice));

                        var result = _api.SendPrice(item);
                        if (result.IsSuccess)
                        {
                            var dbListing = db.Listings.GetAll().FirstOrDefault(i => i.Id == item.ListingEntityId);
                            if (dbListing != null)
                            {
                                dbListing.PriceUpdateRequested = false;
                                db.Commit();
                            }
                        }
                    }

                    //var newFeed = new Feed()
                    //{
                    //    Market = (int)Market,
                    //    MarketplaceId = MarketplaceId,
                    //    Type = (int)FeedType,
                    //    IsProcessed = false,
                    //    SubmitDate = _time.GetAppNowTime()
                    //};
                    //db.Feeds.Add(newFeed);
                    //db.Commit();

                    //_log.Info("Feed id=" + newFeed.Id);

                    //var submitResult = _api.SubmitPriceFeed(newFeed.Id.ToString(),
                    //    items,
                    //    _feedBaseDirectory);

                    //if (submitResult.IsSuccess)
                    //{
                    //    _log.Info("Walmart feed id=" + submitResult.Data);

                    //    newFeed.AmazonIdentifier = submitResult.Data;
                    //    db.Commit();

                    //    _log.Info("Feed submitted, feedId=" + newFeed.AmazonIdentifier);
                    //}
                    //else
                    //{
                    //    _log.Info("Feed DIDN'T submitted, mark feed as deleted");

                    //    newFeed.Deleted = true;
                    //    db.Commit();
                    //}
                }
            }
        }