public void CreateShopifyListings()
        {
            using (var db = _dbFactory.GetRWDb())
            {
                var styleIds = db.Items.GetAll()
                               .Where(p => p.Market == (int)MarketType.Groupon)
                               .Select(i => new {
                    i.ParentASIN,
                    i.StyleId,
                    i.Market,
                    i.MarketplaceId
                })
                               .Distinct()
                               .ToList();

                var existMarketItems = db.Items.GetAll().Where(i => i.Market == (int)MarketType.Shopify &&
                                                               i.MarketplaceId == MarketplaceKeeper.ShopifyEveryCh).ToList();

                IList <MessageString> messages;
                foreach (var styleInfo in styleIds)
                {
                    if (existMarketItems.Any(i => i.StyleId == styleInfo.StyleId))
                    {
                        continue;
                    }

                    var model = _autoCreateListingService.CreateFromParentASIN(db,
                                                                               styleInfo.ParentASIN,
                                                                               styleInfo.Market,
                                                                               styleInfo.MarketplaceId,
                                                                               false,
                                                                               false,
                                                                               0,
                                                                               out messages);

                    model.Market        = (int)MarketType.Shopify;
                    model.MarketplaceId = MarketplaceKeeper.ShopifyEveryCh;

                    if (model.Variations.Select(i => i.StyleId).Distinct().Count() != 1)
                    {
                        _log.Info("Parent ASIN is multilisting");
                        continue;
                    }

                    _autoCreateListingService.PrepareData(model);
                    _autoCreateListingService.Save(model, null, db, _time.GetAppNowTime(), null);
                }
            }
        }
Ejemplo n.º 2
0
        public void CreateMagentoListings()
        {
            using (var db = _dbFactory.GetRWDb())
            {
                var styleIds = (from i in db.Items.GetAll()
                                join l in db.Listings.GetAll() on i.Id equals l.ItemId
                                join sic in db.StyleItemCaches.GetAll() on i.StyleItemId equals sic.Id
                                where i.MarketplaceId == MarketplaceKeeper.AmazonComMarketplaceId &&
                                !l.IsRemoved
                                select new {
                    i.ParentASIN,
                    i.StyleId,
                    i.Market,
                    i.MarketplaceId,
                    sic.RemainingQuantity
                })
                               .Distinct()
                               .OrderByDescending(i => i.RemainingQuantity)
                               .Take(1000)
                               .ToList();

                var existMarketStyleIds = db.Items.GetAll()
                                          .Where(i => i.Market == (int)MarketType.Magento &&
                                                 i.StyleId.HasValue)
                                          .Select(i => i.StyleId)
                                          .ToList();

                IList <MessageString> messages;
                foreach (var styleInfo in styleIds)
                {
                    if (existMarketStyleIds.Any(i => i == styleInfo.StyleId))
                    {
                        continue;
                    }

                    var model = _autoCreateListingService.CreateFromParentASIN(db,
                                                                               styleInfo.ParentASIN,
                                                                               styleInfo.Market,
                                                                               styleInfo.MarketplaceId,
                                                                               false,
                                                                               false,
                                                                               0,
                                                                               out messages);

                    if (model == null)
                    {
                        _log.Info("Empty model");
                        continue;
                    }

                    model.Market        = (int)MarketType.Magento;
                    model.MarketplaceId = "";

                    //if (model.Variations.Select(i => i.StyleId).Distinct().Count() != 1
                    //    && model.Variations.Select(i => i.StyleId).Distinct().Count() != 2)
                    //{
                    //    _log.Info("Parent ASIN is multilisting");
                    //    continue;
                    //}

                    _autoCreateListingService.PrepareData(model);
                    _autoCreateListingService.Save(model, null, db, _time.GetAppNowTime(), null);

                    var newItems = db.Items.GetAll().Where(i => i.Market == (int)MarketType.Magento &&
                                                           i.ParentASIN == model.ASIN).ToList();
                    existMarketStyleIds.AddRange(newItems.Where(i => i.StyleId.HasValue).Select(i => i.StyleId).Distinct());
                }
            }
        }
Ejemplo n.º 3
0
        public void CreateJetListings()
        {
            using (var db = _dbFactory.GetRWDb())
            {
                var groupByStyle = from siCache in db.StyleItemCaches.GetAll()
                                   group siCache by siCache.StyleId
                                   into byStyle
                                   select new
                {
                    StyleId = byStyle.Key,
                    Qty     = byStyle.Sum(s => s.RemainingQuantity)
                };

                var query = from s in db.Styles.GetAll()
                            join sCache in db.StyleCaches.GetAll() on s.Id equals sCache.Id
                            join qty in groupByStyle on s.Id equals qty.StyleId
                            orderby qty.Qty descending
                            where !s.Deleted
                            select new
                {
                    StyleId       = s.Id,
                    StyleString   = s.StyleID,
                    ParentASIN    = sCache.AssociatedASIN,
                    Market        = sCache.AssociatedMarket,
                    MarketplaceId = sCache.AssociatedMarketplaceId,
                    Qty           = qty.Qty
                };

                var styleInfoList = query
                                    .Where(p => p.MarketplaceId == MarketplaceKeeper.AmazonComMarketplaceId &&
                                           p.Qty > 100)
                                    .Take(1000)
                                    .ToList();

                var existMarketItems = db.Items.GetAll().Where(i => i.Market == (int)MarketType.Jet).ToList();

                var newStyleInfoes = styleInfoList.Where(s => existMarketItems.All(i => i.StyleId != s.StyleId)).ToList();

                var styleBlackList = new string[]
                {
                    //"21FZ045TBFDZ" //Created manually
                };

                IList <MessageString> messages;
                foreach (var styleInfo in newStyleInfoes)
                {
                    _log.Info("Creating styleId=" + styleInfo.StyleString + " (" + styleInfo.StyleId + ")" + ", ASIN=" +
                              styleInfo.ParentASIN);
                    if (existMarketItems.Any(i => i.StyleId == styleInfo.StyleId))
                    {
                        _log.Info("Skipped, style already exists");
                        continue;
                    }

                    //NOTE: temporary skip
                    if (styleBlackList.Contains(styleInfo.StyleString))
                    {
                        continue;
                    }


                    var model = _autoCreateListingService.CreateFromParentASIN(db,
                                                                               styleInfo.ParentASIN,
                                                                               styleInfo.Market.Value,
                                                                               styleInfo.MarketplaceId,
                                                                               false,
                                                                               false,
                                                                               0,
                                                                               out messages);

                    if (model.Variations == null)
                    {
                        _log.Info("Skipped, variations is NULL");
                        continue;
                    }

                    if (model.Variations.Count == 0)
                    {
                        _log.Info("Skipped, no variations");
                        continue;
                    }

                    if (model.Variations.Count > 12)
                    {
                        _log.Info("Skipped, a lot of variations");
                        continue;
                    }

                    model.Market        = (int)MarketType.Jet;
                    model.MarketplaceId = null;

                    _autoCreateListingService.PrepareData(model);
                    _autoCreateListingService.Save(model, null, db, _time.GetAppNowTime(), null);

                    //Add to exist list the new items
                    existMarketItems.AddRange(model.Variations.Select(i => new Item()
                    {
                        StyleId = i.StyleId
                    }));
                }
            }
        }