public void SendInventoryUpdates(WooCommerceApi api)
        {
            _log.Info("Begin SendInventoryUpdates");
            var sleeper = new StepSleeper(TimeSpan.FromSeconds(2), 1);

            using (var db = _dbFactory.GetRWDb())
            {
                var listings   = db.Listings.GetQuantityUpdateRequiredList(api.Market, api.MarketplaceId);
                var itemIdList = listings.Select(l => l.ItemId).ToList();
                var items      = db.Items.GetAllViewAsDto().Where(i => itemIdList.Contains(i.Id)).ToList();

                var listingWithErrorList = new List <Listing>();

                foreach (var listing in listings)
                {
                    var item = items.FirstOrDefault(i => i.Id == listing.ItemId);
                    if (item != null &&
                        !String.IsNullOrEmpty(item.SourceMarketId))
                    {
                        sleeper.NextStep();
                        var result = api.UpdateQuantityByLocation(long.Parse(item.SourceMarketId),
                                                                  listing.RealQuantity,
                                                                  true);

                        if (result.Status == CallStatus.Success)
                        {
                            listing.QuantityUpdateRequested = false;
                            listing.AmazonRealQuantity      = listing.RealQuantity;
                            db.Commit();
                            _log.Info("Qty updated, listingId=" + listing.ListingId + ", sendQty=" +
                                      listing.RealQuantity);
                        }
                        else
                        {
                            listingWithErrorList.Add(listing);
                            _log.Info("Can't update qty, result=" + result.ToString());
                        }
                    }
                    else
                    {
                        if (item == null)
                        {
                            _log.Warn("Can't find item, for listing=" + listing.ListingId);
                        }
                        else
                        {
                            if (!item.DropShipperId.HasValue)
                            {
                                _log.Warn("Item hasn't dropShipperId, itemId=" + item.Id);
                            }
                            if (String.IsNullOrEmpty(item?.SourceMarketId))
                            {
                                _log.Warn("Item hasn't sourceMarketId, itemId=" + item.Id);
                            }
                        }
                    }
                }
            }
            _log.Info("End SendInventoryUpdates");
        }
Esempio n. 2
0
        public void GetOrders()
        {
            var api = new WooCommerceApi(_log, _time, "", _apiKey, _apiSecret, _endPoint);

            var results = api.GetOrders(_log, DateTime.Now.AddDays(-60), null);

            _log.Info(results.ToString());
        }
Esempio n. 3
0
        public void GetProducts()
        {
            var api = new WooCommerceApi(_log, _time, "", _apiKey, _apiSecret, _endPoint);

            List <string> asinWithErrors;
            var           results = api.GetItems(_log, _time, null, ItemFillMode.Defualt, out asinWithErrors);

            _log.Info(results.ToString());
        }
Esempio n. 4
0
 public ImportWooCommerceListingDataThread(WooCommerceApi api,
                                           long companyId,
                                           ISystemMessageService messageService,
                                           TimeSpan?callbackInterval,
                                           TimeSpan betweenProcessingInverval)
     : base("ImportWooCommerceListingData", companyId, messageService, callbackInterval)
 {
     _api = api;
     _betweenProcessingInverval = betweenProcessingInverval;
 }
        public void SendPriceUpdates(WooCommerceApi api)
        {
            _log.Info("Begin SendPriceUpdates");
            var today   = _time.GetAppNowTime().Date;
            var sleeper = new StepSleeper(TimeSpan.FromSeconds(2), 1);

            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.Unpublished) &&
                                i.Market == (int)api.Market &&
                                (i.MarketplaceId == api.MarketplaceId || String.IsNullOrEmpty(api.MarketplaceId)) &&
                                !l.IsRemoved
                                select new ItemDTO()
                {
                    ListingEntityId = l.Id,
                    SourceMarketId  = i.SourceMarketId,
                    SKU             = l.SKU,
                    StyleId         = i.StyleId,
                    CurrentPrice    = l.CurrentPrice,
                    ListPrice       = s.MSRP,
                    SalePrice       = sale != null ? sale.SalePrice : null,
                    SaleStartDate   = sale != null ? sale.SaleStartDate : null,
                    SaleEndDate     = sale != null ? sale.SaleEndDate : null,
                };

                var listingWithErrorList = new List <ItemDTO>();

                var items = itemQuery.ToList();

                foreach (var item in items)
                {
                    //var item = items.FirstOrDefault(i => i.Id == listing.ItemId);
                    if (!String.IsNullOrEmpty(item.SourceMarketId))
                    {
                        sleeper.NextStep();

                        var result = api.UpdatePrice(StringHelper.TryGetLong(item.SourceMarketId).Value,
                                                     item.CurrentPrice,
                                                     item.ListPrice
                                                     //item.SalePrice,
                                                     //item.SaleStartDate,
                                                     //item.SaleEndDate
                                                     );

                        if (result.Status == CallStatus.Success)
                        {
                            var dbListing = db.Listings.GetAll().FirstOrDefault(i => i.Id == item.ListingEntityId);
                            dbListing.PriceUpdateRequested = false;
                            dbListing.AmazonCurrentPrice   = item.CurrentPrice;
                            db.Commit();
                            _log.Info("Price updated, listingId=" + dbListing.ListingId + ", newPrice=" +
                                      dbListing.CurrentPrice);
                        }
                        else
                        {
                            listingWithErrorList.Add(item);
                            _log.Info("Can't update qty, result=" + result.ToString());
                        }
                    }
                    else
                    {
                        if (String.IsNullOrEmpty(item.SourceMarketId))
                        {
                            _log.Warn("Item hasn't sourceMarketId, itemId=" + item.Id);
                        }
                    }
                }
            }
            _log.Info("End SendPriceUpdates");
        }