Пример #1
0
        public CallWalmartProcessing(ILogService log,
                                     ITime time,
                                     ICacheService cacheService,
                                     IDbFactory dbFactory,
                                     IEmailService emailService,
                                     IItemHistoryService itemHistoryService,
                                     WalmartApi walmartApi,
                                     CompanyDTO company)
        {
            _log                = log;
            _time               = time;
            _dbFactory          = dbFactory;
            _cacheService       = cacheService;
            _walmartApi         = walmartApi;
            _company            = company;
            _emailService       = emailService;
            _itemHistoryService = itemHistoryService;

            _actionService  = new SystemActionService(_log, _time);
            _htmlScraper    = new HtmlScraperService(log, time, dbFactory);
            _barcodeService = new BarcodeService(log, time, dbFactory);

            _openApi = new WalmartOpenApi(_log, "trn9fdghvb8p9gjj9j6bvjwx");
            _autoCreateListingService = new AutoCreateWalmartListingService(log,
                                                                            time,
                                                                            dbFactory,
                                                                            _cacheService,
                                                                            _barcodeService,
                                                                            _emailService,
                                                                            _openApi,
                                                                            itemHistoryService,
                                                                            AppSettings.IsDebug);
        }
Пример #2
0
        public CallMessagesResult <bool> UpdateFeed(ILogService log,
                                                    ITime time,
                                                    IDbFactory dbFactory,
                                                    ISystemActionService actionService,
                                                    IItemHistoryService itemHistoryService,
                                                    long companyId)
        {
            var sourceFeed = Path.Combine(UrlHelper.GetImportCatalogFeedPath(), FileName);

            var marketplaceManager = new MarketplaceKeeper(dbFactory, false);

            marketplaceManager.Init();

            IWalmartApi api = (IWalmartApi) new MarketFactory(marketplaceManager.GetAll(), time, log, dbFactory, null)
                              .GetApi(companyId, MarketType.WalmartCA, null);

            var service = new WalmartListingInfoReader(log, time, api, dbFactory, actionService, itemHistoryService, null, null);

            service.UpdateListingInfo(sourceFeed);

            return(new CallMessagesResult <bool>()
            {
                Data = true
            });
        }
 public AutoCreateAmazonUSPrimeListingService(ILogService log,
                                              ITime time,
                                              IDbFactory dbFactory,
                                              IItemHistoryService itemHistoryService)
 {
     _log                = log;
     _time               = time;
     _dbFactory          = dbFactory;
     _itemHistoryService = itemHistoryService;
 }
 public AutoCreateEBayListingService(ILogService log,
                                     ITime time,
                                     IDbFactory dbFactory,
                                     ICacheService cacheService,
                                     IBarcodeService barcodeService,
                                     IEmailService emailService,
                                     IItemHistoryService itemHistoryService,
                                     bool isDebug) : base(log, time, dbFactory, cacheService, barcodeService, emailService, itemHistoryService, isDebug)
 {
     _log       = log;
     _time      = time;
     _dbFactory = dbFactory;
 }
Пример #5
0
        public AmazonReportService(AmazonReportType reportType,
                                   long companyId,
                                   AmazonApi api,
                                   ILogService log,
                                   ITime time,
                                   IDbFactory dbFactory,
                                   ISyncInformer syncInfo,
                                   IStyleManager styleManager,
                                   INotificationService notificationService,
                                   IStyleHistoryService styleHistoryService,
                                   IItemHistoryService itemHistoryService,
                                   ISystemActionService actionService,
                                   IReportParser parser,
                                   string path = "")
        {
            _log       = log;
            _time      = time;
            _dbFactory = dbFactory;

            _api = api;

            _reportInfo = new AmazonReportInfo();
            _reportInfo.ReportRequestId = String.Empty;

            _path          = path;
            _companyId     = companyId;
            _syncInfo      = syncInfo;
            _reportType    = reportType;
            _parser        = parser;
            _actionService = actionService;

            var parseContext = new ParseContext()
            {
                Log                 = log,
                Time                = time,
                DbFactory           = dbFactory,
                ActionService       = actionService,
                StyleManager        = styleManager,
                NotificationService = notificationService,
                StyleHistoryService = styleHistoryService,
                ItemHistoryService  = itemHistoryService,
                SyncInformer        = syncInfo,
                CompanyId           = companyId
            };

            _parser.Init(parseContext);

            _log.Info(string.Format("Path: {0}", path));
        }
Пример #6
0
 public AutoCreateAmazonAUListingService(ILogService log,
                                         ITime time,
                                         IDbFactory dbFactory,
                                         ICacheService cacheService,
                                         IBarcodeService barcodeService,
                                         IEmailService emailService,
                                         ISystemActionService actionService,
                                         IItemHistoryService itemHistoryService,
                                         bool isDebug) : base(log, time, dbFactory, cacheService, barcodeService, emailService, itemHistoryService, isDebug)
 {
     _log           = log;
     _time          = time;
     _dbFactory     = dbFactory;
     _actionService = actionService;
 }
 public ListingLineProcessing(ParseContext parseContext,
                              ITime time,
                              bool canCreateStyleInfo)
 {
     _log                 = parseContext.Log;
     _companyId           = parseContext.CompanyId;
     _styleManager        = parseContext.StyleManager;
     _syncInfo            = parseContext.SyncInformer;
     _notificationService = parseContext.NotificationService;
     _styleHistoryService = parseContext.StyleHistoryService;
     _itemHistoryService  = parseContext.ItemHistoryService;
     _actionService       = parseContext.ActionService;
     _time                = time;
     _canCreateStyleInfo  = canCreateStyleInfo;
 }
 public AutoCreateWalmartCAListingService(ILogService log,
                                          ITime time,
                                          IDbFactory dbFactory,
                                          ICacheService cacheService,
                                          IBarcodeService barcodeService,
                                          IEmailService emailService,
                                          IItemHistoryService itemHistoryService,
                                          bool isDebug) : base(log, time, dbFactory, cacheService, barcodeService, emailService, itemHistoryService, isDebug)
 {
     _log            = log;
     _time           = time;
     _dbFactory      = dbFactory;
     _cacheService   = cacheService;
     _barcodeService = barcodeService;
     _emailService   = emailService;
     _isDebug        = isDebug;
 }
 public WalmartListingInfoReader(ILogService log,
                                 ITime time,
                                 IWalmartApi api,
                                 IDbFactory dbFactory,
                                 ISystemActionService actionService,
                                 IItemHistoryService itemHistoryService,
                                 string reportBaseDirectory,
                                 string feedBaseDirectory)
 {
     _api                 = api;
     _log                 = log;
     _time                = time;
     _dbFactory           = dbFactory;
     _actionService       = actionService;
     _itemHistoryService  = itemHistoryService;
     _reportBaseDirectory = reportBaseDirectory;
     _feedBaseDirectory   = feedBaseDirectory;
 }
Пример #10
0
        public static void CopyToMarketplaces(IUnitOfWork db,
                                              ICacheService cache,
                                              IBarcodeService barcodeService,
                                              ISystemActionService actionService,
                                              IAutoCreateListingService autoCreateListingService,
                                              IItemHistoryService itemHistoryService,
                                              int id,
                                              DateTime when,
                                              long?by,
                                              IList <ItemMarketViewModel> toMarketplaces,
                                              out IList <MessageString> messages)
        {
            var parent = db.ParentItems.GetAsDTO(id);

            messages = new List <MessageString>();

            foreach (var toMarketplace in toMarketplaces)
            {
                var model = ItemEditViewModel.CreateFromParentASIN(db,
                                                                   autoCreateListingService,
                                                                   parent.ASIN,
                                                                   parent.Market,
                                                                   parent.MarketplaceId,
                                                                   false, //NOTE: false - ex.: exclude to copy FBP to Walmart
                                                                   out messages);

                model.Id            = null;
                model.Market        = toMarketplace.Market;
                model.MarketplaceId = toMarketplace.MarketplaceId;
                //model.OnHold = true;

                var parentBaseASIN = SkuHelper.RemoveSKULastIndex(model.ASIN);
                var parentIndex    = 0;
                while (db.ParentItems.GetAsDTO(parentBaseASIN + ((parentIndex == 0) ? "" : "-" + parentIndex), (MarketType)toMarketplace.Market, toMarketplace.MarketplaceId) != null)
                {
                    parentIndex++;
                }
                var parentSKU = parentBaseASIN + ((parentIndex == 0) ? "" : "-" + parentIndex);

                var forceReplace = model.VariationList.Any(s => (s.Size ?? "").Contains("/"));

                model.ASIN = parentSKU;

                foreach (var item in model.VariationList)
                {
                    item.Id = null;

                    if (model.Market == (int)MarketType.Walmart ||
                        model.Market == (int)MarketType.WalmartCA)
                    {
                        item.Barcode = null;
                        item.AutoGeneratedBarcode = true;
                    }

                    if (item.StyleItemId.HasValue)
                    {
                        var sourceUSDPrice = item.Price;
                        var fromCurrency   = PriceHelper.GetCurrencyAbbr((MarketType)parent.Market, parent.MarketplaceId);
                        if (fromCurrency != PriceHelper.USDSymbol)
                        {
                            sourceUSDPrice = PriceHelper.ConvertToUSD(item.Price, fromCurrency);
                        }

                        var rateForMarketplace = RateHelper.GetRatesByStyleItemId(db, item.StyleItemId.Value);
                        var newPrice           = RateHelper.CalculateForMarket((MarketType)toMarketplace.Market,
                                                                               toMarketplace.MarketplaceId,

                                                                               sourceUSDPrice,
                                                                               rateForMarketplace[MarketplaceKeeper.AmazonComMarketplaceId],
                                                                               rateForMarketplace[MarketplaceKeeper.AmazonCaMarketplaceId],
                                                                               rateForMarketplace[MarketplaceKeeper.AmazonUkMarketplaceId],
                                                                               rateForMarketplace[MarketplaceKeeper.AmazonAuMarketplaceId],
                                                                               RateService.GetMarketShippingAmount(MarketType.Amazon, MarketplaceKeeper.AmazonComMarketplaceId),
                                                                               RateService.GetMarketShippingAmount((MarketType)toMarketplace.Market, toMarketplace.MarketplaceId),
                                                                               RateService.GetMarketExtraAmount((MarketType)toMarketplace.Market, toMarketplace.MarketplaceId));

                        if (newPrice.HasValue)
                        {
                            item.Price = newPrice.Value;
                        }
                    }

                    if (db.Listings.CheckForExistenceSKU(item.SKU,
                                                         (MarketType)toMarketplace.Market,
                                                         toMarketplace.MarketplaceId))
                    {
                        var baseSKU = item.StyleString + "-" + SizeHelper.PrepareSizeForSKU(item.StyleSize, forceReplace);
                        var index   = parentIndex;

                        while (db.Listings.CheckForExistenceSKU(SkuHelper.SetSKUMiddleIndex(baseSKU, index),
                                                                (MarketType)toMarketplace.Market,
                                                                toMarketplace.MarketplaceId))
                        {
                            index++;
                        }

                        item.SKU = SkuHelper.SetSKUMiddleIndex(baseSKU, index);
                    }
                }

                model.Save(db,
                           cache,
                           barcodeService,
                           actionService,
                           itemHistoryService,
                           when,
                           by);
            }
        }
Пример #11
0
        public void UpdateItemsForParentItem(
            IItemHistoryService itemChangeHistory,
            string calledFrom,
            string parentAsin,
            int market,
            string marketplaceId,
            IList <ItemDTO> items,
            DateTime when,
            long?by)
        {
            var dbExistItems = GetFiltered(l => l.ParentASIN == parentAsin &&
                                           l.Market == market &&
                                           l.MarketplaceId == marketplaceId).ToList();

            var existItemIdList = dbExistItems.Select(i => i.Id).ToList();
            var dbExistListings = unitOfWork.GetSet <Listing>()
                                  .Where(l => existItemIdList.Contains(l.ItemId))
                                  .ToList();

            var existListingIdList = dbExistListings.Select(l => l.Id).ToList();

            var newItems = items.Where(l => !l.ListingEntityId.HasValue || l.ListingEntityId == 0 || !existListingIdList.Contains(l.ListingEntityId.Value)).ToList();

            foreach (var dbListing in dbExistListings)
            {
                var existItem = items.FirstOrDefault(l => l.ListingEntityId == dbListing.Id);
                var dbItem    = dbExistItems.FirstOrDefault(l => l.Id == dbListing.ItemId);

                if (existItem != null)
                {
                    var hasChanges = dbItem.StyleItemId != existItem.StyleItemId ||
                                     dbItem.StyleId != existItem.StyleId ||
                                     dbItem.Size != existItem.Size ||
                                     dbItem.Color != existItem.Color ||
                                     dbItem.Title != existItem.Name ||
                                     dbItem.Barcode != existItem.Barcode ||
                                     dbItem.PrimaryImage != existItem.ImageUrl ||
                                     dbItem.ParentASIN != existItem.ParentASIN;

                    if (hasChanges)
                    {
                        dbItem.ParentASIN = existItem.ParentASIN;

                        dbItem.StyleString = existItem.StyleString;
                        dbItem.StyleId     = existItem.StyleId;
                        dbItem.StyleItemId = existItem.StyleItemId;

                        if (dbItem.Size != existItem.Size)
                        {
                            if (itemChangeHistory != null)
                            {
                                itemChangeHistory.AddRecord(dbItem.Id,
                                                            ItemHistoryHelper.SizeKey,
                                                            dbItem.Size,
                                                            calledFrom,
                                                            existItem.Size,
                                                            null,
                                                            by);
                            }
                        }

                        dbItem.Size  = existItem.Size;
                        dbItem.Color = existItem.Color;
                        dbItem.Title = existItem.Name;

                        if (!String.IsNullOrEmpty(existItem.Barcode)) //NOTE: may came empty when disable mode
                        {
                            if (dbItem.Barcode != existItem.Barcode)
                            {
                                if (itemChangeHistory != null)
                                {
                                    itemChangeHistory.AddRecord(dbItem.Id,
                                                                ItemHistoryHelper.BarcodeKey,
                                                                dbItem.Barcode,
                                                                calledFrom,
                                                                existItem.Barcode,
                                                                null,
                                                                by);
                                }

                                dbItem.Barcode = existItem.Barcode;
                            }
                        }

                        dbItem.PrimaryImage = existItem.ImageUrl;

                        dbItem.UpdateDate = when;
                        dbItem.UpdatedBy  = by;
                    }

                    if (dbItem.ItemPublishedStatus != (int)PublishedStatuses.None &&
                        dbItem.ItemPublishedStatus != (int)PublishedStatuses.New &&
                        dbItem.ItemPublishedStatus != (int)PublishedStatuses.Unpublished &&
                        dbItem.ItemPublishedStatus != (int)PublishedStatuses.HasUnpublishRequest)
                    {
                        dbItem.ItemPublishedStatus     = (int)PublishedStatuses.HasChanges;
                        dbItem.ItemPublishedStatusDate = when;
                    }
                    //NOTE: override with manuall if not empty
                    if (existItem.PublishedStatus != (int)PublishedStatuses.None)
                    {
                        dbItem.ItemPublishedStatus     = existItem.PublishedStatus;
                        dbItem.ItemPublishedStatusDate = when;
                    }

                    if (dbListing != null)
                    {
                        var hasListingChanges = dbListing.CurrentPrice != existItem.CurrentPrice ||
                                                dbListing.IsPrime != existItem.IsPrime ||
                                                dbListing.SKU != existItem.SKU ||
                                                dbListing.IsDefault != existItem.IsDefault;
                        if (hasListingChanges)
                        {
                            if (dbListing.CurrentPrice != existItem.CurrentPrice)
                            {
                                itemChangeHistory.LogListingPrice(PriceChangeSourceType.EnterNewPrice,
                                                                  dbListing.Id,
                                                                  dbListing.SKU,
                                                                  existItem.CurrentPrice,
                                                                  dbListing.CurrentPrice,
                                                                  when,
                                                                  by);

                                dbListing.CurrentPrice = existItem.CurrentPrice;
                            }

                            dbListing.IsPrime = existItem.IsPrime;

                            if (!String.IsNullOrEmpty(existItem.SKU)) //NOTE: may came empty when disable mode
                            {
                                if (dbListing.SKU != existItem.SKU)
                                {
                                    if (itemChangeHistory != null)
                                    {
                                        itemChangeHistory.AddRecord(dbItem.Id,
                                                                    ItemHistoryHelper.SKUKey,
                                                                    dbListing.SKU,
                                                                    calledFrom,
                                                                    existItem.SKU,
                                                                    null,
                                                                    by);
                                    }

                                    dbListing.SKU = existItem.SKU;
                                }
                            }
                            dbListing.IsDefault = existItem.IsDefault;

                            dbListing.UpdateDate = when;
                            dbListing.UpdatedBy  = by;
                        }

                        dbListing.QuantityUpdateRequested     = true;
                        dbListing.QuantityUpdateRequestedDate = when;
                        dbListing.PriceUpdateRequested        = true;
                        dbListing.PriceUpdateRequestedDate    = when;
                    }
                }
                else
                {
                    dbListing.IsRemoved = true;
                    unitOfWork.Commit();
                }
            }

            unitOfWork.Commit();

            foreach (var newItem in newItems)
            {
                var dbItem = new Item()
                {
                    ParentASIN    = newItem.ParentASIN,
                    Market        = market,
                    MarketplaceId = marketplaceId,

                    ASIN = StringHelper.Substring(newItem.ASIN, 50),

                    StyleString = newItem.StyleString,
                    StyleId     = newItem.StyleId,
                    StyleItemId = newItem.StyleItemId,
                    Size        = StringHelper.Substring(newItem.Size, 50),
                    Color       = StringHelper.Substring(newItem.Color, 50),

                    Barcode      = newItem.Barcode,
                    PrimaryImage = newItem.ImageUrl,

                    Title = newItem.Name,

                    ItemPublishedStatus     = (int)PublishedStatuses.New,
                    ItemPublishedStatusDate = when,

                    CreateDate = when,
                    CreatedBy  = by
                };
                Add(dbItem);
                unitOfWork.Commit();

                if (itemChangeHistory != null)
                {
                    itemChangeHistory.AddRecord(dbItem.Id,
                                                ItemHistoryHelper.SizeKey,
                                                null,
                                                calledFrom,
                                                dbItem.Size,
                                                null,
                                                by);
                }

                var dbListing = new Listing()
                {
                    ItemId        = dbItem.Id,
                    Market        = market,
                    MarketplaceId = marketplaceId,

                    ListingId = newItem.ListingId,
                    SKU       = StringHelper.Substring(newItem.SKU, 100),
                    IsDefault = newItem.IsDefault,

                    CurrentPrice = newItem.CurrentPrice,
                    RealQuantity = newItem.RealQuantity,

                    PriceUpdateRequested    = true,
                    QuantityUpdateRequested = true,

                    CreateDate = when,
                    CreatedBy  = by
                };

                unitOfWork.Listings.Add(dbListing);
                unitOfWork.Commit();

                newItem.ListingEntityId = dbListing.Id;
                newItem.Id = dbItem.Id;
            }
        }
Пример #12
0
        public Item StoreItemIfNotExist(IItemHistoryService itemHistory,
                                        string calledFrom,
                                        ItemDTO dto,
                                        MarketType market,
                                        string marketplaceId,
                                        long companyId,
                                        DateTime?when)
        {
            if (!ArgumentHelper.CheckMarket(market))
            {
                throw new ArgumentNullException("market");
            }
            if (!ArgumentHelper.CheckMarketplaceId(market, marketplaceId))
            {
                throw new ArgumentNullException("marketplaceId");
            }

            var item = GetByASIN(dto.ASIN, market, marketplaceId);

            if (item == null)
            {
                item = new Item
                {
                    ASIN          = dto.ASIN,
                    Market        = (int)market,
                    MarketplaceId = marketplaceId,

                    SourceMarketId = dto.SourceMarketId,

                    Title      = dto.Name,
                    ParentASIN = dto.ParentASIN ?? String.Empty,
                    Size       = StringHelper.Substring(dto.Size, 50),
                    Barcode    = dto.Barcode,

                    //SKU = dto.SKU,
                    StyleString = dto.StyleString,
                    StyleId     = dto.StyleId,
                    StyleItemId = dto.StyleItemId,

                    IsAmazonParentASIN   = dto.IsAmazonParentASIN,
                    LastUpdateFromAmazon = dto.LastUpdateFromAmazon,
                    IsExistOnAmazon      = dto.IsExistOnAmazon,

                    CreateDate  = when,
                    CompanyId   = companyId,
                    Description = dto.Description,

                    //Additional fields
                    PrimaryImage     = dto.ImageUrl,
                    BrandName        = dto.BrandName,
                    Type             = StringHelper.Substring(dto.Type, 50),
                    ListPrice        = dto.ListPrice,
                    Color            = StringHelper.Substring(dto.Color, 50),
                    Department       = dto.Department,
                    Features         = dto.Features,
                    AdditionalImages = dto.AdditionalImages,
                    SearchKeywords   = dto.SearchKeywords
                };
                Add(item);

                unitOfWork.Commit();

                if (itemHistory != null)
                {
                    itemHistory.AddRecord(item.Id,
                                          ItemHistoryHelper.SizeKey,
                                          null,
                                          calledFrom,
                                          item.Size,
                                          null,
                                          null);
                }
            }

            return(item);
        }