public WooCommerceOrdersSynchronizer(ILogService log, IMarketApi api, CompanyDTO company, ISettingsService settings, ISyncInformer syncInfo, IList <IShipmentApi> rateProviders, IQuantityManager quantityManager, IEmailService emailService, IOrderValidatorService validatorService, IOrderHistoryService orderHistoryService, ICacheService cacheService, ISystemActionService systemAction, ICompanyAddressService companyAddress, ITime time, IWeightService weightService, ISystemMessageService messageService) : base(log, api, company, settings, syncInfo, rateProviders, quantityManager, emailService, validatorService, orderHistoryService, cacheService, systemAction, companyAddress, time, weightService, messageService) { }
protected SyncResult SyncAllNewOrders(CancellationToken?token, ILogService log, IMarketApi api, MarketType market, Func <ILogService, IMarketApi, ISyncInformer, string, IList <ListingOrderDTO> > getOrderItemsFromMarketFunc, ISyncInformer syncInfo, IList <IShipmentApi> rateProviders, IQuantityManager quantityManager, ISettingsService settings, IEmailService emailService, IOrderValidatorService validatorService, ICacheService cacheService, ICompanyAddressService companyAddress, DateTime syncMissedFrom, ITime time) { try { log.Info("Get missed orders"); var statusList = new List <string> { OrderStatusEnumEx.Canceled, OrderStatusEnumEx.Shipped, OrderStatusEnumEx.Unshipped, OrderStatusEnumEx.Pending }; //NOTE: On API level there status will be converted on eBay status var allOrders = api.GetOrders(log, syncMissedFrom, statusList).ToList(); if (allOrders.Any()) { var result = ProcessNewOrdersPack(token, log, api, getOrderItemsFromMarketFunc, rateProviders, validatorService, syncInfo, settings, quantityManager, emailService, cacheService, companyAddress, allOrders, time); if (!result.IsSuccess) { syncInfo.AddWarning("", "The orders pack processing has failed"); return(new SyncResult() { IsSuccess = false }); } return(result); } return(new SyncResult() { IsSuccess = true, ProcessedOrders = new List <SyncResultOrderInfo>() }); } catch (Exception ex) { syncInfo.AddError(null, "Error when storing new unshipped orders", ex); log.Error("Error when storing new unshipped orders", ex); return(new SyncResult() { IsSuccess = false }); } }
protected SyncResult UpdateExistingUnshippedOrders(CancellationToken?token, ILogService log, IMarketApi api, Func <ILogService, IMarketApi, ISyncInformer, string, IList <ListingOrderDTO> > getOrderItemsFromMarketFunc, ISyncInformer syncInfo, IList <IShipmentApi> rateProviders, IQuantityManager quantityManager, IEmailService emailService, IOrderValidatorService validatorService, IList <string> excludeOrderIdList, ICompanyAddressService companyAddress, ITime time) { IList <Order> ordersToUpdate = new List <Order>(); try { using (var db = new UnitOfWork(log)) { var existOrders = db.Orders.GetOrdersByStatus(api.Market, api.MarketplaceId, new[] { OrderStatusEnumEx.Pending, OrderStatusEnumEx.Unshipped, OrderStatusEnumEx.PartiallyShipped } ).ToList(); if (excludeOrderIdList != null) { ordersToUpdate = existOrders.Where(o => !excludeOrderIdList.Contains(o.AmazonIdentifier)).ToList(); } else { ordersToUpdate = existOrders; } log.Info("Orders to update count:" + ordersToUpdate.Count + " (existing in DB=" + existOrders.Count + ", exclude list=" + (excludeOrderIdList != null ? excludeOrderIdList.Count.ToString() : "[null]") + ")"); var index = 0; var step = 50; while (index < ordersToUpdate.Count) { var ordersToProcess = ordersToUpdate.Skip(index).Take(step).ToList(); log.Info("Start process orders from api, from=" + index + ", count=" + ordersToProcess.Count); if (!ProcessExistOrdersPack(token, log, api, getOrderItemsFromMarketFunc, syncInfo, db, rateProviders, quantityManager, emailService, validatorService, companyAddress, ordersToProcess, time)) { syncInfo.AddWarning("", "The pending orders pack processing has failed"); //Break cycle if pack processing is fail, something wrong (m.b. unavailable Db, m.b. parallel sync) return(new SyncResult() { IsSuccess = false }); } index += step; syncInfo.PingSync(); } } return(new SyncResult() { IsSuccess = true, ProcessedOrders = ordersToUpdate.Select(o => new SyncResultOrderInfo() { OrderId = o.AmazonIdentifier, OrderStatus = o.OrderStatus }).ToList() }); } catch (Exception ex) { LogError(log, syncInfo, ex, "", "Error when updating existing orders"); return(new SyncResult() { IsSuccess = false }); } }
public IOrderSynchronizer GetForMarket(IMarketApi api, ILogService log, CompanyDTO company, ISettingsService settings, ISyncInformer syncInfo, IList <IShipmentApi> rateProviders, IQuantityManager quantityManager, IEmailService emailService, IOrderValidatorService validatorService, IOrderHistoryService orderHistoryService, ICacheService cacheService, ISystemActionService systemAction, ICompanyAddressService companyAddress, ITime time, IWeightService weightService, ISystemMessageService messageService) { IOrderSynchronizer synchronizer = null; switch (api.Market) { case MarketType.Amazon: case MarketType.AmazonEU: case MarketType.AmazonAU: synchronizer = new AmazonOrdersSynchronizer(log, api, company, settings, syncInfo, rateProviders, quantityManager, emailService, validatorService, orderHistoryService, cacheService, systemAction, companyAddress, time, weightService, messageService); break; case MarketType.eBay: synchronizer = new EBayOrdersSynchronizer(log, api, company, settings, syncInfo, rateProviders, quantityManager, emailService, validatorService, orderHistoryService, cacheService, systemAction, companyAddress, time, weightService, messageService); break; case MarketType.Magento: synchronizer = new MagentoOrdersSynchronizer(log, api, company, settings, syncInfo, rateProviders, quantityManager, emailService, validatorService, orderHistoryService, cacheService, systemAction, companyAddress, time, weightService, messageService); break; case MarketType.Groupon: synchronizer = new GrouponOrdersSynchronizer(log, api, company, settings, syncInfo, rateProviders, quantityManager, emailService, validatorService, orderHistoryService, cacheService, systemAction, companyAddress, time, weightService, messageService); break; case MarketType.Shopify: synchronizer = new ShopifyOrdersSynchronizer(log, api, company, settings, syncInfo, rateProviders, quantityManager, emailService, validatorService, orderHistoryService, cacheService, systemAction, companyAddress, time, weightService, messageService); break; case MarketType.WooCommerce: synchronizer = new WooCommerceOrdersSynchronizer(log, api, company, settings, syncInfo, rateProviders, quantityManager, emailService, validatorService, orderHistoryService, cacheService, systemAction, companyAddress, time, weightService, messageService); break; case MarketType.Walmart: case MarketType.WalmartCA: synchronizer = new WalmartOrdersSynchronizer(log, api, company, settings, syncInfo, rateProviders, quantityManager, emailService, validatorService, orderHistoryService, cacheService, systemAction, companyAddress, time, weightService, messageService); break; case MarketType.Jet: synchronizer = new JetOrdersSynchronizer(log, api, company, settings, syncInfo, rateProviders, quantityManager, emailService, validatorService, orderHistoryService, cacheService, systemAction, companyAddress, time, weightService, messageService); break; case MarketType.DropShipper: synchronizer = new DSOrdersSynchronizer(log, api, company, settings, syncInfo, rateProviders, quantityManager, emailService, validatorService, orderHistoryService, cacheService, systemAction, companyAddress, time, weightService, messageService); break; case MarketType.OverStock: synchronizer = new SupplierOasisOrdersSynchronizer(log, api, company, settings, syncInfo, rateProviders, quantityManager, emailService, validatorService, orderHistoryService, cacheService, systemAction, companyAddress, time, weightService, messageService); break; case MarketType.OfflineOrders: synchronizer = new UserOrdersSynchronizer(log, api, company, settings, syncInfo, rateProviders, quantityManager, emailService, validatorService, orderHistoryService, cacheService, systemAction, companyAddress, time, weightService, messageService); break; default: throw new NotImplementedException("MarketType not supported=" + api.Market.ToString()); break; } return(synchronizer); }
protected SyncResult SyncAllUnshippedOrders(CancellationToken?cancel, ILogService log, IMarketApi api, Func <ILogService, IMarketApi, ISyncInformer, string, IList <ListingOrderDTO> > getOrderItemsFromMarketFunc, ISyncInformer syncInfo, IList <IShipmentApi> rateProviders, IQuantityManager quantityManager, ISettingsService settings, IEmailService emailService, IOrderValidatorService validatorService, ICacheService cacheService, ICompanyAddressService companyAddress, DateTime syncMissedFrom, ITime time) { try { log.Info("Get missed orders"); SyncResult result = new SyncResult(); var statusList = new List <string> { OrderStatusEnumEx.Unshipped, OrderStatusEnumEx.PartiallyShipped, OrderStatusEnumEx.Canceled }; var unshippedOrders = api.GetOrders(log, syncMissedFrom, statusList).ToList(); if (unshippedOrders.Any()) { result = ProcessNewOrdersPack(cancel, log, api, getOrderItemsFromMarketFunc, rateProviders, validatorService, syncInfo, settings, quantityManager, emailService, cacheService, companyAddress, unshippedOrders, time); if (!result.IsSuccess) { syncInfo.AddWarning("", "The orders pack processing has failed"); return(new SyncResult() { IsSuccess = false }); } } return(new SyncResult() { IsSuccess = true, //NOTE: Return all unshipped orders for correct calculation total orders on Amazon //unprocessed orders actual didn't updated (we can safely skip processing of it) ProcessedOrders = result.ProcessedOrders, SkippedOrders = result.SkippedOrders, /*unshippedOrders.Select(o => new SyncResultOrderInfo() * { * OrderId = o.OrderId, * OrderStatus = o.OrderStatus * }).ToList()*/ }); } catch (Exception ex) { syncInfo.AddError(null, "Error when storing new unshipped orders", ex); log.Error("Error when storing new unshipped orders", ex); return(new SyncResult() { IsSuccess = false }); } }
/// <summary> /// Requested new pending orders (from last exist pending order date) /// </summary> /// <returns></returns> protected SyncResult StoreNewPendingOrders(CancellationToken?token, ILogService log, IMarketApi api, Func <ILogService, IMarketApi, ISyncInformer, string, IList <ListingOrderDTO> > getOrderItemsFromMarketFunc, IList <IShipmentApi> rateProviders, IOrderValidatorService validatorService, IEmailService emailService, ISyncInformer syncInfo, ISettingsService settings, IQuantityManager quantityManager, ICacheService cacheService, ICompanyAddressService companyAddress, ITime time) { try { using (var db = new UnitOfWork(_log)) { var lastPending = db.Orders .GetFiltered(o => o.OrderStatus == OrderStatusEnumEx.Pending && o.Market == (int)api.Market && o.MarketplaceId == api.MarketplaceId) .OrderBy(o => o.Id).FirstOrDefault(); var date = lastPending != null && lastPending.OrderDate.HasValue ? lastPending.OrderDate : null; log.Info(date != null ? "Last pending order date: " + date.Value : "No pending orders!"); var updatedAfter = date ?? DateHelper.GetAmazonNowTime().AddDays(-1); log.Info(string.Format("Process Orders created since {0}", updatedAfter)); var statusList = new List <string> { OrderStatusEnum.Pending.Str() }; var pendingOrders = api.GetOrders(log, updatedAfter, statusList).ToList(); log.Info("Total pending orders:" + pendingOrders.Count()); syncInfo.PingSync(); var result = ProcessNewOrdersPack(token, log, api, getOrderItemsFromMarketFunc, rateProviders, validatorService, syncInfo, settings, quantityManager, emailService, cacheService, companyAddress, pendingOrders, time); if (!result.IsSuccess) { syncInfo.AddWarning("", "The orders pack processing has failed"); return(new SyncResult() { IsSuccess = false }); } return(result); } } catch (Exception ex) { syncInfo.AddError(null, "Error when storing new orders", ex); log.Error("Error when storing new orders", ex); return(new SyncResult() { IsSuccess = false }); } }