Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public CallEBayProcessing(ILogService log,
                                  ITime time,
                                  ICacheService cacheService,
                                  IDbFactory dbFactory,
                                  IStyleManager styleManager,
                                  eBayApi eBayApi,
                                  IEmailService emailService,
                                  CompanyDTO company)
        {
            _log                                 = log;
            _time                                = time;
            _dbFactory                           = dbFactory;
            _cacheService                        = cacheService;
            _styleManager                        = styleManager;
            _descriptionTemplatePath             = Path.Combine(AppSettings.TemplateDirectory, TemplateHelper.EBayDescriptionTemplateName);
            _descriptionMultiListingTemplatePath = Path.Combine(AppSettings.TemplateDirectory, TemplateHelper.EBayDescriptionMultiListingTemplateName);

            _eBayApi      = eBayApi;
            _company      = company;
            _emailService = emailService;

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

            var itemHistoryService = new ItemHistoryService(_log, _time, _dbFactory);

            _barcodeService           = new BarcodeService(log, time, dbFactory);
            _autoCreateListingService = new AutoCreateEBayListingService(_log, _time, dbFactory, cacheService, _barcodeService, _emailService, itemHistoryService, AppSettings.IsDebug);
        }
Exemplo n.º 3
0
 public OrderValidatorService(
     ILogService log,
     IDbFactory dbFactory,
     IEmailService emailService,
     ISettingsService settings,
     IOrderHistoryService orderHistory,
     ISystemActionService actionService,
     IPriceService priceService,
     IHtmlScraperService htmlScraper,
     IAddressService addressService,
     AddressDTO returnAddress,
     IShipmentApi stampsRateApi,
     ITime time,
     CompanyDTO company)
 {
     _log            = log;
     _dbFactory      = dbFactory;
     _time           = time;
     _emailService   = emailService;
     _settings       = settings;
     _orderHistory   = orderHistory;
     _actionService  = actionService;
     _priceService   = priceService;
     _htmlScraper    = htmlScraper;
     _addressService = addressService;
     _returnAddress  = returnAddress;
     _stampsRateApi  = stampsRateApi;
     _company        = company;
 }
        public static MemoryStream ExportToExcelUS(ILogService log,
                                                   ITime time,
                                                   IMarketCategoryService categoryService,
                                                   IHtmlScraperService htmlScraper,
                                                   IMarketApi marketApi,
                                                   IUnitOfWork db,
                                                   CompanyDTO company,
                                                   string asin,
                                                   MarketType market,
                                                   string marketplaceId,
                                                   bool useStyleImage,
                                                   out string filename)
        {
            var models = GetItemsFor(log,
                                     time,
                                     categoryService,
                                     htmlScraper,
                                     marketApi,
                                     db,
                                     company,
                                     asin,
                                     ExportToExcelMode.Normal,
                                     null,
                                     market,
                                     marketplaceId,
                                     useStyleImage ? UseStyleImageModes.StyleImage : UseStyleImageModes.ListingImage,
                                     out filename);

            return(ExcelHelper.ExportIntoFile(HttpContext.Current.Server.MapPath(USTemplatePath),
                                              "Template",
                                              models));
        }
Exemplo n.º 5
0
        public CallSupplieroasisProcessing(ILogService log,
                                           ITime time,
                                           ICacheService cacheService,
                                           IEmailService emailService,
                                           IDbFactory dbFactory,
                                           CompanyDTO company)
        {
            _dbFactory             = dbFactory;
            _cacheService          = cacheService;
            _barcodeService        = new BarcodeService(log, time, dbFactory);
            _trackingNumberService = new TrackingNumberService(log, time, dbFactory);
            _log          = log;
            _time         = time;
            _emailService = emailService;
            _company      = company;

            _weightService  = new WeightService();
            _messageService = new SystemMessageService(_log, _time, dbFactory);
            _actionService  = new SystemActionService(_log, _time);
            _htmlScraper    = new HtmlScraperService(log, time, dbFactory);

            var itemHistoryService = new ItemHistoryService(log, time, dbFactory);

            _autoCreateListingService = new AutoCreateNonameListingService(_log, _time, dbFactory, cacheService, _barcodeService, _emailService, itemHistoryService, AppSettings.IsDebug);
        }
 public PersonatorAddressCheckService(ILogService log,
                                      IHtmlScraperService htmlScraperService,
                                      string customerId)
 {
     _customerId  = customerId;
     _log         = log;
     _htmlScraper = htmlScraperService;
 }
Exemplo n.º 7
0
 public CallTestHttpParsing(ILogService log,
                            ITime time,
                            IDbFactory dbFactory)
 {
     _log         = log;
     _time        = time;
     _dbFactory   = dbFactory;
     _htmlScraper = new HtmlScraperService(log, time, dbFactory);
 }
Exemplo n.º 8
0
 public CallImageProcessing(IDbFactory dbFactory,
                            ITime time,
                            ILogService log)
 {
     _dbFactory   = dbFactory;
     _time        = time;
     _log         = log;
     _htmlScraper = new HtmlScraperService(_log, _time, _dbFactory);
 }
 public AddressNotServedByUSPSChecker(ILogService log,
                                      IHtmlScraperService htmlScraper,
                                      IEmailService emailService,
                                      ITime time)
 {
     _time         = time;
     _emailService = emailService;
     _htmlScraper  = htmlScraper;
     _log          = log;
 }
Exemplo n.º 10
0
 public ImageManager(ILogService log,
                     IHtmlScraperService htmlScraper,
                     IDbFactory dbFactory,
                     ITime time)
 {
     _log         = log;
     _time        = time;
     _htmlScraper = htmlScraper;
     _dbFactory   = dbFactory;
 }
Exemplo n.º 11
0
 public CallAddressProcessing(
     ILogService log,
     ITime time,
     IDbFactory dbFactory,
     CompanyDTO company)
 {
     _log         = log;
     _company     = company;
     _time        = time;
     _dbFactory   = dbFactory;
     _htmlScraper = new HtmlScraperService(log, time, dbFactory);
 }
Exemplo n.º 12
0
        public CallWalmartCAProcessing(ILogService log,
                                       ITime time,
                                       ICacheService cacheService,
                                       IDbFactory dbFactory,
                                       IEmailService emailService,
                                       WalmartCAApi walmartCAApi,
                                       CompanyDTO company)
        {
            _log          = log;
            _time         = time;
            _dbFactory    = dbFactory;
            _cacheService = cacheService;
            _walmartCAApi = walmartCAApi;
            _company      = company;
            _emailService = emailService;

            var itemHistoryService = new ItemHistoryService(_log, _time, _dbFactory);

            _actionService            = new SystemActionService(_log, _time);
            _htmlScraper              = new HtmlScraperService(log, time, dbFactory);
            _barcodeService           = new BarcodeService(log, time, dbFactory);
            _autoCreateListingService = new AutoCreateWalmartCAListingService(log, time, dbFactory, _cacheService, _barcodeService, _emailService, itemHistoryService, AppSettings.IsDebug);
        }
        public static IList <ExcelWFSProductUSViewModel> GetItemsFor(ILogService log,
                                                                     ITime time,
                                                                     IMarketCategoryService categoryService,
                                                                     IHtmlScraperService htmlScraper,
                                                                     IMarketApi marketApi,
                                                                     IUnitOfWork db,
                                                                     CompanyDTO company,
                                                                     string asin,
                                                                     ExportToExcelMode exportMode,
                                                                     IList <FBAItemInfo> fbaItems,
                                                                     MarketType market,
                                                                     string marketplaceId,
                                                                     UseStyleImageModes useStyleImageMode,
                                                                     out string filename)
        {
            filename = null;

            var items = ItemExportHelper.GetParentItemAndChilds(log,
                                                                time,
                                                                htmlScraper,
                                                                marketApi,
                                                                db,
                                                                company,
                                                                asin,
                                                                fbaItems,
                                                                exportMode,
                                                                market,
                                                                marketplaceId);

            var parent   = items.Item1; // db.ParentItems.GetAsDTO(asin);
            var children = items.Item2; // db.Items.GetAllActualExAsDto().Where(i => i.ParentASIN == asin).ToList();

            var models = GetItemsFor(db, categoryService, exportMode, fbaItems, parent, children, useStyleImageMode, out filename);

            return(models);
        }
        public static MemoryStream ExportToWFSExcel(long pickListId,
                                                    IUnitOfWork db,
                                                    IDbFactory dbFactory,
                                                    CompanyDTO company,
                                                    IMarketCategoryService categoryService,
                                                    IHtmlScraperService htmlScraper,
                                                    ILogService log,
                                                    ITime time,
                                                    out string filename)
        {
            var resultItems = new List <ExcelWFSProductUSViewModel>();

            var pickListEntries = db.FBAPickListEntries.GetAllAsDto()
                                  .Where(p => p.FBAPickListId == pickListId)
                                  .ToList();

            IList <FBAItemInfo> fbaItems = pickListEntries.Select(e => new FBAItemInfo()
            {
                ParentASIN = e.ListingParentASIN,
                ASIN       = e.ListingASIN,
                SKU        = e.ListingSKU,
                Quantity   = e.Quantity,
            }).ToList();

            var marketplaceManager = new MarketplaceKeeper(dbFactory, false);

            marketplaceManager.Init();

            IMarketApi api = new MarketFactory(marketplaceManager.GetAll(), time, log, dbFactory, null)
                             .GetApi(AccessManager.Company.Id, MarketType.Amazon, MarketplaceKeeper.AmazonComMarketplaceId);

            var parentASINList = fbaItems.Select(i => i.ParentASIN).Distinct().ToList();

            foreach (var parentASIN in parentASINList)
            {
                var childFBAItems = fbaItems.Where(f => f.ParentASIN == parentASIN).ToList();
                var newItems      = ExcelWFSProductUSViewModel.GetItemsFor(log,
                                                                           time,
                                                                           categoryService,
                                                                           htmlScraper,
                                                                           api,
                                                                           db,
                                                                           company,
                                                                           parentASIN,
                                                                           ExportToExcelMode.FBA,
                                                                           childFBAItems,
                                                                           MarketType.Amazon,
                                                                           MarketplaceKeeper.AmazonComMarketplaceId,
                                                                           UseStyleImageModes.Auto,
                                                                           out filename);

                var parentItem       = newItems.FirstOrDefault(i => i.Parentage == ExcelHelper.ParentageParent);
                var wasAddedAny      = false;
                var notExistNewItems = new List <ExcelWFSProductUSViewModel>();
                foreach (var item in newItems.Where(i => i.Parentage != ExcelHelper.ParentageParent))
                {
                    var existListing = db.Listings.GetAll().FirstOrDefault(l => l.SKU == item.SKU && !l.IsRemoved);
                    if (existListing == null)
                    {
                        notExistNewItems.Add(item);
                        wasAddedAny = true;
                    }
                }
                if (wasAddedAny)
                {
                    if (parentItem != null)
                    {
                        resultItems.Add(parentItem);
                    }
                    resultItems.AddRange(notExistNewItems);
                }
            }

            var output = ExcelHelper.ExportIntoFile(HttpContext.Current.Server.MapPath(ExcelWFSProductUSViewModel.USTemplatePath),
                                                    "Template",
                                                    resultItems);

            filename = String.Format("WFSListings_{0}.xls", time.GetAppNowTime().ToString("MM_dd_yyyy_hh_mm_ss"));

            return(output);
        }
Exemplo n.º 15
0
        public static IList <ExcelProductUKViewModel> GetItemsFor(ILogService log,
                                                                  ITime time,
                                                                  IMarketCategoryService categoryService,
                                                                  IHtmlScraperService htmlScraper,
                                                                  IMarketApi marketApi,
                                                                  IUnitOfWork db,
                                                                  CompanyDTO company,
                                                                  string asin,
                                                                  MarketType market,
                                                                  string marketplaceId,
                                                                  UseStyleImageModes useStyleImageMode,
                                                                  out string filename)
        {
            var gbpExchangeRate = PriceHelper.GBPtoUSD;
            var today           = time.GetAppNowTime();

            var models = new List <ExcelProductUKViewModel>();
            var items  = ItemExportHelper.GetParentItemAndChilds(log,
                                                                 time,
                                                                 htmlScraper,
                                                                 marketApi,
                                                                 db,
                                                                 company,
                                                                 asin,
                                                                 null,
                                                                 ExportToExcelMode.Normal,
                                                                 market,
                                                                 marketplaceId);

            var parent     = items.Item1; // db.ParentItems.GetAsDTO(asin);
            var children   = items.Item2; // db.Items.GetAllActualExAsDto().Where(i => i.ParentASIN == asin).ToList();
            var firstChild = children.FirstOrDefault();

            FeatureValueDTO subLicense          = null;
            string          material            = null;
            string          materialComposition = null;
            string          itemStyle           = null;

            if (firstChild != null && firstChild.StyleId.HasValue)
            {
                subLicense          = db.FeatureValues.GetValueByStyleAndFeatureId(firstChild.StyleId.Value, StyleFeatureHelper.SUB_LICENSE1);
                itemStyle           = ItemExportHelper.GetFeatureValue(db.FeatureValues.GetValueByStyleAndFeatureId(firstChild.StyleId.Value, StyleFeatureHelper.ITEMSTYLE));
                material            = ItemExportHelper.GetFeatureValue(db.FeatureValues.GetValueByStyleAndFeatureId(firstChild.StyleId.Value, StyleFeatureHelper.MATERIAL));
                materialComposition = ItemExportHelper.GetFeatureValue(db.FeatureValues.GetValueByStyleAndFeatureId(firstChild.StyleId.Value, StyleFeatureHelper.MATERIAL_COMPOSITION));
            }

            if (parent != null)
            {
                var variationType = ItemExportHelper.GetVariationType(children != null ? children.Select(ch => ch.Color).ToList() : null);

                string  childBrandName   = null;
                decimal?childListPrice   = null;
                string  childDepartment  = null;
                string  childSize        = null;
                string  childStyleString = null;

                IList <string> childFeatures = new List <string>();
                //IList<string> searchTermList = new List<string>();

                //if (!String.IsNullOrEmpty(parent.SearchKeywords))
                //    searchTermList = parent.SearchKeywords.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();

                var searchTerms = (parent.SearchKeywords ?? "").Replace(";", ", ");
                searchTerms = ItemExportHelper.PrepareSearchTerms(searchTerms);

                if (firstChild != null)
                {
                    childBrandName = children.Select(c => c.BrandName).FirstOrDefault();
                    childFeatures  = !String.IsNullOrEmpty(firstChild.Features)
                        ? firstChild.Features.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList()
                        : new List <string>();

                    childListPrice   = firstChild.ListPrice;
                    childDepartment  = firstChild.Department;
                    childSize        = firstChild.Size;
                    childStyleString = firstChild.StyleString;
                }

                //For simplicity, w can just use for parent SKU (unless it exist) style-%parentASIN%.
                string parentSku = parent.SKU;
                if (String.IsNullOrEmpty(parentSku))
                {
                    parentSku = childStyleString + "-" + parent.ASIN;
                }

                var gender       = childDepartment ?? parent.Department ?? "";
                var sizeType     = ItemExportHelper.GetSizeType(childSize);
                var categoryInfo = categoryService.GetCategory(market, marketplaceId, itemStyle, gender, sizeType);

                //var itemType = ItemExportHelper.GetItemType(itemStyle);
                var    newItemType   = categoryInfo.Key1;// ItemExportHelper.ItemTypeConverter(childSize ?? "", itemType, itemStyle, gender);
                var    newDepartment = StringHelper.GetFirstNotEmpty(categoryInfo.Key2, ItemExportHelper.DepartmentConverter(gender, newItemType, sizeType));
                string clothingType  = categoryInfo.Key3;
                var    parentImage   = ItemExportHelper.ImageConverter(StringHelper.GetFirstNotEmpty(
                                                                           parent.LargeImage != null ? parent.LargeImage.Image : null,
                                                                           parent.ImageSource));

                var replaces = new Dictionary <string, string>()
                {
                    { "Nightgown", "Nighty" },
                    { "Nightys", "Nighties" },
                    { "nightgown", "nighty" },
                    { "nighty", "nighties" },
                    { "pajama", "pyjama" },
                    { "Pajama", "Pyjama" },
                };

                var hasCotton = StringHelper.GetInOneOfStrings("Cotton", new List <string>()
                {
                    searchTerms,
                    parent.AmazonName,
                    parent.Description,
                    firstChild != null ? firstChild.Features : null
                });

                if (String.IsNullOrEmpty(materialComposition))
                {
                    if (hasCotton)
                    {
                        materialComposition = "Cotton";
                    }
                    else
                    {
                        materialComposition = "Polyester";
                    }
                }

                models.Add(new ExcelProductUKViewModel
                {
                    SKU           = parentSku,
                    Title         = StringHelper.Replaces(parent.AmazonName, replaces),
                    ASIN          = parent.ASIN,
                    UPC           = "",
                    ProductId     = "",// "ASIN",
                    BrandName     = parent.BrandName ?? childBrandName,
                    Description   = parent.Description,
                    ClothingType  = clothingType,
                    Update        = "Update",
                    StandardPrice = "",

                    //SuggestedPrice = childListPrice.HasValue ? PriceHelper.Convert(childListPrice.Value / 100, gbpExchangeRate, false).ToString("G") : "",
                    Currency = "", // childListPrice.HasValue ? "GBP" : "",

                    Quantity = "",

                    RecommendedBrowseNodes1 = ExcelProductUKViewModel.GetRecommendedBrowseNodes1(newDepartment, childSize, newItemType),

                    KeyProductFeatures1 = childFeatures.Count > 0 ? childFeatures[0] : String.Empty,
                    KeyProductFeatures2 = childFeatures.Count > 1 ? childFeatures[1] : String.Empty,
                    KeyProductFeatures3 = childFeatures.Count > 2 ? childFeatures[2] : String.Empty,
                    KeyProductFeatures4 = childFeatures.Count > 3 ? childFeatures[3] : String.Empty,
                    KeyProductFeatures5 = childFeatures.Count > 4 ? childFeatures[4] : String.Empty,

                    SearchTerms1 = searchTerms,
                    //SearchTerms2 = searchTermList.Count > 1 ? searchTermList[1] : String.Empty,
                    //SearchTerms3 = searchTermList.Count > 2 ? searchTermList[2] : String.Empty,
                    //SearchTerms4 = searchTermList.Count > 3 ? searchTermList[3] : String.Empty,
                    //SearchTerms5 = searchTermList.Count > 4 ? searchTermList[4] : String.Empty,

                    MainImageURL   = parentImage,
                    Parentage      = "Parent",
                    VariationTheme = variationType,

                    MaterialComposition = materialComposition,
                    Department          = newDepartment,
                    Color = "",
                });

                foreach (var child in children)
                {
                    var styleImages = child.StyleId.HasValue ?
                                      db.StyleImages
                                      .GetAllAsDto()
                                      .Where(im => im.StyleId == child.StyleId.Value && im.IsDefault)
                                      .ToList()
                            : null;

                    IList <string> features = !String.IsNullOrEmpty(child.Features)
                        ? child.Features.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList()
                        : new List <string>();

                    var childImage = ItemExportHelper.ImageConverter(StringHelper.GetFirstNotEmpty(
                                                                         child.LargeImageUrl,
                                                                         child.ImageUrl));

                    if (useStyleImageMode == UseStyleImageModes.StyleImage)
                    {
                        if (styleImages != null && styleImages.Any())
                        {
                            childImage = styleImages.First().Image;
                        }
                    }

                    var itemPrice = child.SalePrice.HasValue && child.SaleStartDate < today
                        ? child.SalePrice.Value
                        : child.CurrentPrice;

                    models.Add(new ExcelProductUKViewModel
                    {
                        StyleId     = child.StyleId,
                        StyleItemId = child.StyleItemId,

                        SKU          = child.SKU,
                        Title        = StringHelper.Replaces(child.Name, replaces),
                        ASIN         = child.ASIN,
                        UPC          = child.Barcode,
                        ProductId    = "UPC",// "ASIN",
                        BrandName    = child.BrandName,
                        Description  = parent.Description,
                        ClothingType = clothingType,
                        Update       = "Update",

                        StandardPrice = CorrectUKPrice(PriceHelper.Convert(itemPrice, gbpExchangeRate, true)).ToString("G"),
                        //SuggestedPrice = child.ListPrice.HasValue ? PriceHelper.Convert(child.ListPrice.Value / 100, gbpExchangeRate, false).ToString("G") : "",
                        Currency = "GBP",
                        Quantity = child.RealQuantity.ToString("G"),// "1", // i.Quantity.ToString("G"),

                        KeyProductFeatures1 = features.Count > 0 ? features[0] : String.Empty,
                        KeyProductFeatures2 = features.Count > 1 ? features[1] : String.Empty,
                        KeyProductFeatures3 = features.Count > 2 ? features[2] : String.Empty,
                        KeyProductFeatures4 = features.Count > 3 ? features[3] : String.Empty,
                        KeyProductFeatures5 = features.Count > 4 ? features[4] : String.Empty,

                        SearchTerms1 = searchTerms,
                        //SearchTerms2 = searchTermList.Count > 1 ? searchTermList[1] : String.Empty,
                        //SearchTerms3 = searchTermList.Count > 2 ? searchTermList[2] : String.Empty,
                        //SearchTerms4 = searchTermList.Count > 3 ? searchTermList[3] : String.Empty,
                        //SearchTerms5 = searchTermList.Count > 4 ? searchTermList[4] : String.Empty,


                        RecommendedBrowseNodes1 = ExcelProductUKViewModel.GetRecommendedBrowseNodes1(newDepartment, childSize, newItemType),

                        MainImageURL     = childImage,
                        Parentage        = "Child",
                        ParentSKU        = parentSku,
                        RelationshipType = "Variation",
                        VariationTheme   = variationType,
                        Department       = newDepartment,
                        Color            = child.Color,

                        MaterialComposition = materialComposition,
                        Size = ItemExportHelper.PrepareSize(ExcelProductUKViewModel.SizeConverter(child.Size, material), gender),
                    });
                }

                if (children.Count > 0 &&
                    useStyleImageMode == UseStyleImageModes.StyleImage)
                {
                    models[0].MainImageURL = models[1].MainImageURL;
                }
            }

            filename = models[0].SKU + "_" + (subLicense != null ? subLicense.Value : "none") + "_UK.xls";

            return(models);
        }
Exemplo n.º 16
0
        public void Create(ILogService log,
                           ITime time,
                           IQuantityManager quantityManager,
                           IDbFactory dbFactory,
                           IWeightService weightService,
                           IShippingService shippingService,
                           IAutoCreateListingService createListingService,
                           ISettingsService settingService,
                           IEmailService emailService,
                           ISystemActionService actionService,
                           IHtmlScraperService htmlScraper,
                           IOrderHistoryService orderHistory,
                           IPriceService priceService,
                           CompanyDTO company,
                           DateTime when,
                           long?by)
        {
            var syncInfo      = new EmptySyncInformer(log, SyncType.Orders);
            var market        = (int)MarketType.OfflineOrders;
            var marketplaceId = MarketplaceKeeper.ManuallyCreated;

            var orderItems = new List <ListingOrderDTO>();

            using (var db = dbFactory.GetRWDb())
            {
                var index = 1;
                foreach (var item in Items)
                {
                    var dbItem = db.Items.GetAll().FirstOrDefault(i => i.Market == market &&
                                                                  i.MarketplaceId == marketplaceId &&
                                                                  i.StyleItemId == item.StyleItemId);

                    if (dbItem == null)
                    {
                        var itemPrice = item.ItemPrice; // db.Items.GetAllViewActual()
                                                        //.FirstOrDefault(i => i.Market == (int)MarketType.Amazon
                                                        //    && i.MarketplaceId == MarketplaceKeeper.AmazonComMarketplaceId)?.CurrentPrice;

                        log.Info("Request create listing, market=" + market
                                 + ", marketplaceId=" + marketplaceId);

                        IList <MessageString> messages = new List <MessageString>();
                        //Create New
                        var model = createListingService.CreateFromStyle(db,
                                                                         item.StyleId.Value,
                                                                         (MarketType)market,
                                                                         marketplaceId,
                                                                         out messages);

                        model.Variations.ForEach(v => v.CurrentPrice = itemPrice);

                        createListingService.Save(model,
                                                  "",
                                                  db,
                                                  when,
                                                  by);

                        dbItem = db.Items.GetAll().FirstOrDefault(i => i.Market == market &&
                                                                  i.MarketplaceId == marketplaceId &&
                                                                  i.StyleItemId == item.StyleItemId);
                    }

                    var dbListing = db.Listings.GetAll().FirstOrDefault(l => l.Market == market &&
                                                                        l.MarketplaceId == marketplaceId &&
                                                                        l.ItemId == dbItem.Id);

                    orderItems.Add(new ListingOrderDTO()
                    {
                        ASIN            = dbItem.ASIN,
                        SKU             = dbListing.SKU,
                        ItemPaid        = item.ItemPrice,
                        ItemPrice       = item.ItemPrice,
                        ItemGrandPrice  = item.ItemPrice,
                        StyleId         = dbItem.StyleId,
                        StyleID         = dbItem.StyleString,
                        StyleItemId     = dbItem.StyleItemId,
                        Market          = dbItem.Market,
                        MarketplaceId   = dbItem.MarketplaceId,
                        QuantityOrdered = item.Quantity,
                        ItemOrderId     = index.ToString(),
                        SourceListingId = dbListing.Id,
                    });

                    index++;
                }

                OrderNumber = db.Orders.GetAll()
                              .Where(o => o.Market == (int)market &&
                                     o.MarketplaceId == marketplaceId)
                              .OrderByDescending(o => o.Id).FirstOrDefault()?.AmazonIdentifier;

                if (String.IsNullOrEmpty(OrderNumber))
                {
                    OrderNumber = "1000";
                }
                else
                {
                    OrderNumber = ((StringHelper.TryGetInt(OrderNumber) ?? 1000) + 1).ToString();
                }
            }

            var dtoOrder = new DTOOrder()
            {
                Market            = market,
                MarketplaceId     = marketplaceId,
                OrderDate         = OrderDate,
                OrderStatus       = "Unshipped",
                SourceOrderStatus = "Unshipped",
                OrderId           = OrderNumber,
                CustomerOrderId   = OrderNumber,
                MarketOrderId     = OrderNumber,

                AmazonEmail      = ToAddress.Email,
                BuyerEmail       = ToAddress.Email,
                PersonName       = ToAddress.FullName,
                BuyerName        = ToAddress.FullName,
                ShippingAddress1 = ToAddress.Address1,
                ShippingAddress2 = ToAddress.Address2,
                ShippingCity     = ToAddress.City,
                ShippingCountry  = ToAddress.Country,
                ShippingZip      = ToAddress.Zip,
                ShippingZipAddon = ToAddress.ZipAddon,
                ShippingPhone    = ToAddress.Phone,
                ShippingState    = StringHelper.GetFirstNotEmpty(ToAddress.USAState, ToAddress.NonUSAState),

                ShippingPaid  = 0,
                ShippingPrice = 0,
                TotalPaid     = Items.Sum(i => i.ItemPrice),
                TotalPrice    = Items.Sum(i => i.ItemPrice),

                Quantity = Items.Sum(i => i.Quantity),

                InitialServiceType    = ShippingService,
                ShippingService       = ShippingService,
                SourceShippingService = ShippingService,

                Items = orderItems,
            };

            var userOrderApi = new UserOrderApi(new List <DTOOrder>()
            {
                dtoOrder
            });

            var serviceFactory       = new ServiceFactory();
            var addressCheckServices = serviceFactory.GetAddressCheckServices(log,
                                                                              time,
                                                                              dbFactory,
                                                                              company.AddressProviderInfoList);
            var companyAddress = new CompanyAddressService(company);
            var addressService = new AddressService(addressCheckServices, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), companyAddress.GetPickupAddress(MarketIdentifier.Empty()));

            var rateProviders = serviceFactory.GetShipmentProviders(log,
                                                                    time,
                                                                    dbFactory,
                                                                    weightService,
                                                                    company.ShipmentProviderInfoList,
                                                                    null,
                                                                    null,
                                                                    null,
                                                                    null);

            var stampsRateProvider = rateProviders.FirstOrDefault(r => r.Type == ShipmentProviderType.Stamps);

            var validatorService = new OrderValidatorService(log, dbFactory, emailService, settingService, orderHistory, actionService,
                                                             priceService, htmlScraper, addressService, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), stampsRateProvider, time, company);
            var orderHistoryService = new OrderHistoryService(log, time, dbFactory);
            var cacheService        = new CacheService(log, time, actionService, quantityManager);

            using (var db = dbFactory.GetRWDb())
            {
                try
                {
                    var orderSyncFactory = new OrderSyncFactory();
                    var synchronizer     = orderSyncFactory.GetForMarket(userOrderApi,
                                                                         log,
                                                                         company,
                                                                         settingService,
                                                                         syncInfo,
                                                                         rateProviders,
                                                                         quantityManager,
                                                                         emailService,
                                                                         validatorService,
                                                                         orderHistoryService,
                                                                         cacheService,
                                                                         actionService,
                                                                         companyAddress,
                                                                         time,
                                                                         weightService,
                                                                         null);

                    if (!String.IsNullOrEmpty(OrderNumber))
                    {
                        synchronizer.ProcessSpecifiedOrder(db, OrderNumber);
                        Messages.Add(MessageString.Success("The order has been successfully created, order #: " + OrderNumber));
                    }
                }
                catch (Exception ex)
                {
                    Messages.Add(MessageString.Error(ex.Message));
                }
            }
        }
Exemplo n.º 17
0
        public static IList <ExcelProductCAViewModel> GetItemsFor(ILogService log,
                                                                  ITime time,
                                                                  IMarketCategoryService categoryService,
                                                                  IHtmlScraperService htmlScraper,
                                                                  IMarketApi marketApi,
                                                                  IUnitOfWork db,
                                                                  CompanyDTO company,
                                                                  string parentAsin,
                                                                  MarketType market,
                                                                  string marketplaceId,
                                                                  UseStyleImageModes useStyleImageMode,
                                                                  out string filename)
        {
            var caExchangeRate = PriceHelper.CADtoUSD;
            var today          = time.GetAppNowTime();

            var models = new List <ExcelProductCAViewModel>();
            var items  = ItemExportHelper.GetParentItemAndChilds(log,
                                                                 time,
                                                                 htmlScraper,
                                                                 marketApi,
                                                                 db,
                                                                 company,
                                                                 parentAsin,
                                                                 null,
                                                                 ExportToExcelMode.Normal,
                                                                 market,
                                                                 marketplaceId);

            var parent     = items.Item1; // db.ParentItems.GetAsDTO(asin);
            var children   = items.Item2; // db.Items.GetAllActualExAsDto().Where(i => i.ParentASIN == asin).ToList();
            var firstChild = children.FirstOrDefault();

            FeatureValueDTO subLicense = null;
            string          itemStyle  = null;

            if (firstChild != null && firstChild.StyleId.HasValue)
            {
                //style = db.Styles.Get(parent.StyleId.Value);
                subLicense = db.FeatureValues.GetValueByStyleAndFeatureId(firstChild.StyleId.Value, StyleFeatureHelper.SUB_LICENSE1);
                itemStyle  = ItemExportHelper.GetFeatureValue(db.FeatureValues.GetValueByStyleAndFeatureId(firstChild.StyleId.Value, StyleFeatureHelper.ITEMSTYLE));
            }


            if (parent != null)
            {
                var variationType = ItemExportHelper.GetVariationType(children != null ? children.Select(ch => ch.Color).ToList() : null);

                string         childBrandName   = null;
                decimal?       childListPrice   = null;
                string         childDepartment  = null;
                string         childSize        = null;
                string         childStyleString = null;
                IList <string> childFeatures    = new List <string>();
                if (firstChild != null)
                {
                    childBrandName = children.Select(c => c.BrandName).FirstOrDefault();
                    childFeatures  = !String.IsNullOrEmpty(firstChild.Features)
                        ? firstChild.Features.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList()
                        : new List <string>();
                    childListPrice   = firstChild.ListPrice;
                    childDepartment  = firstChild.Department;
                    childSize        = firstChild.Size;
                    childStyleString = firstChild.StyleString;
                }

                //For simplicity, w can just use for parent SKU (unless it exist) style-%parentASIN%.
                string parentSku = parent.SKU;
                if (String.IsNullOrEmpty(parentSku))
                {
                    parentSku = childStyleString + "-" + parent.ASIN;
                }

                var gender       = (childDepartment ?? parent.Department ?? "");
                var sizeType     = ItemExportHelper.GetSizeType(childSize);
                var categoryInfo = categoryService.GetCategory(market, marketplaceId, itemStyle, gender, sizeType);
                //var itemType = ItemExportHelper.GetItemType(itemStyle);
                var newItemType   = categoryInfo.Key1;// ItemExportHelper.ItemTypeConverter(childSize ?? "", itemType, itemStyle, gender);
                var newDepartment = StringHelper.GetFirstNotEmpty(categoryInfo.Key2, ItemExportHelper.DepartmentConverter(gender, newItemType, sizeType));
                var parentImage   = ItemExportHelper.ImageConverter(StringHelper.GetFirstNotEmpty(
                                                                        parent.LargeImage != null ? parent.LargeImage.Image : null,
                                                                        parent.ImageSource));

                models.Add(new ExcelProductCAViewModel
                {
                    SKU           = parentSku,// parent.StyleString,
                    Title         = parent.AmazonName,
                    ASIN          = parent.ASIN,
                    ProductId     = "ASIN",
                    ClothingType  = "sleepwear",
                    Manufacturer  = parent.BrandName ?? childBrandName,
                    BrandName     = parent.BrandName ?? childBrandName,
                    Description   = parent.Description,
                    Type          = newItemType,
                    Update        = "Update",
                    StandardPrice = "",

                    SuggestedPrice = childListPrice.HasValue ? Math.Round(PriceHelper.Convert(childListPrice.Value / 100, caExchangeRate, true)).ToString("G") : "",
                    Currency       = childListPrice.HasValue ? "CAD" : "",

                    Quantity = "",

                    KeyProductFeatures1 = childFeatures.Count > 0 ? childFeatures[0] : String.Empty,
                    KeyProductFeatures2 = childFeatures.Count > 1 ? childFeatures[1] : String.Empty,
                    KeyProductFeatures3 = childFeatures.Count > 2 ? childFeatures[2] : String.Empty,
                    KeyProductFeatures4 = childFeatures.Count > 3 ? childFeatures[3] : String.Empty,
                    KeyProductFeatures5 = childFeatures.Count > 4 ? childFeatures[4] : String.Empty,

                    RecommendedBrowseNodes1 = ExcelProductCAViewModel.GetRecommendedBrowseNodes1(newDepartment, childSize, newItemType),

                    MainImageURL   = parentImage,
                    Parentage      = "Parent",
                    VariationTheme = variationType,

                    Department = newDepartment,
                    Color      = "",
                });

                foreach (var child in children)
                {
                    var styleImages = child.StyleId.HasValue ?
                                      db.StyleImages
                                      .GetAllAsDto()
                                      .Where(im => im.StyleId == child.StyleId.Value &&
                                             im.Type != (int)StyleImageType.Swatch)
                                      .ToList()
                                      .OrderByDescending(im => ImageHelper.GetSortIndex(im.Category))
                                      .ThenByDescending(im => im.IsDefault)
                                      .ThenBy(im => im.Id)
                                      .ToList()
                            : null;

                    IList <string> features = !String.IsNullOrEmpty(child.Features)
                        ? child.Features.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList()
                        : new List <string>();

                    var childImage = ItemExportHelper.ImageConverter(StringHelper.GetFirstNotEmpty(
                                                                         child.LargeImageUrl,
                                                                         child.ImageUrl));

                    if (useStyleImageMode == UseStyleImageModes.StyleImage)
                    {
                        if (styleImages != null && styleImages.Any())
                        {
                            childImage = styleImages.First().Image;
                        }
                    }

                    var itemPrice = child.SalePrice.HasValue && child.SaleStartDate < today
                        ? child.SalePrice.Value
                        : child.CurrentPrice;
                    models.Add(new ExcelProductCAViewModel
                    {
                        StyleId     = child.StyleId,
                        StyleItemId = child.StyleItemId,

                        SKU          = child.SKU,
                        Title        = child.Name,
                        ASIN         = child.ASIN,
                        ProductId    = "ASIN",
                        ClothingType = "sleepwear",
                        Manufacturer = child.BrandName,
                        BrandName    = child.BrandName,
                        Description  = parent.Description,
                        Type         = newItemType,
                        Update       = "Update",
                        //StandardPrice = child.Price.ToString("G"),
                        StandardPrice = CorrectCAPrice(PriceHelper.Convert(itemPrice, caExchangeRate, true)).ToString("G"),
                        //SalePrice = child.SalePrice.HasValue && child.SaleStartDate < today ? CorrectCAPrice(PriceHelper.Convert(child.SalePrice.Value, caExchangeRate, true)).ToString("G") : null,
                        SuggestedPrice = child.ListPrice.HasValue ? Math.Round(PriceHelper.Convert(child.ListPrice.Value / 100, caExchangeRate, true)).ToString("G") : "",
                        Currency       = child.ListPrice.HasValue ? "CAD" : "",
                        Quantity       = child.RealQuantity.ToString("G"),// "1", // i.Quantity.ToString("G"),

                        KeyProductFeatures1 = features.Count > 0 ? features[0] : String.Empty,
                        KeyProductFeatures2 = features.Count > 1 ? features[1] : String.Empty,
                        KeyProductFeatures3 = features.Count > 2 ? features[2] : String.Empty,
                        KeyProductFeatures4 = features.Count > 3 ? features[3] : String.Empty,
                        KeyProductFeatures5 = features.Count > 4 ? features[4] : String.Empty,

                        RecommendedBrowseNodes1 = ExcelProductCAViewModel.GetRecommendedBrowseNodes1(newDepartment, child.Size, newItemType),

                        MainImageURL     = childImage,
                        Parentage        = "Child",
                        ParentSKU        = parentSku,
                        RelationshipType = "Variation",
                        VariationTheme   = variationType,
                        Department       = newDepartment,
                        Color            = child.Color,
                        Size             = child.Size,
                        SpecialSize      = child.SpecialSize,
                    });
                }

                //Copy to parent child Type
                if (children.Count > 0)
                {
                    models[0].Type = models[1].Type;
                }

                if (children.Count > 0 &&
                    useStyleImageMode == UseStyleImageModes.StyleImage)
                {
                    models[0].MainImageURL = models[1].MainImageURL;
                }
            }

            filename = models[0].SKU + "_" + (subLicense != null ? subLicense.Value : "none") + "_CA.xls";

            return(models);
        }
Exemplo n.º 18
0
 public ImageRequestingService(ILogService log,
                               IHtmlScraperService htmlScraperService)
 {
     _log         = log;
     _htmlScraper = htmlScraperService;
 }