public ReturnBuilder(IOrderEntityFactory entityFactory, IPricelistRepository priceListRepository, OrderClient client, IOrderService service) { _entityFactory = entityFactory; _priceListRepository = priceListRepository; _client = client; _orderService = service; }
public static Price FindLowestPrice(this IPricelistRepository repository, string[] pricelistIds, string itemId, decimal quantity) { var prices = FindLowestPrices(repository, pricelistIds, new string[] { itemId }, quantity); var result = prices == null || prices.Length == 0 ? null : prices[0]; return(result); }
/// <summary> /// Finds the lowest price for each item using price lists, the price from the 1st price list will be returned, even if it is a higher price. /// </summary> /// <param name="repository">The repository.</param> /// <param name="pricelistIds">The pricelist ids.</param> /// <param name="itemIds">The item ids.</param> /// <param name="quantity">The quantity.</param> /// <returns></returns> public static Price[] FindLowestPrices(this IPricelistRepository repository, string[] pricelistIds, string[] itemIds, decimal quantity) { if (pricelistIds == null || itemIds == null) { return(null); } // create a dynamic price list object with ordering var lists = new List <dynamic>(); int index = 0; foreach (var pl in pricelistIds) { lists.Add(new { name = pl, order = index }); index++; } // get all the prices var prices = repository.GetItemPrices(pricelistIds, itemIds, quantity); // group and sort prices, returning lowest price found in the first price list examined for each item var retVal = (from p in prices join l in lists on p.PricelistId.ToLower() equals l.name.ToLower() select new { p, l.order }) .GroupBy(pl => pl.p.ItemId) .Select(p => p.OrderBy(pl => pl.order) .ThenBy(x => Math.Min(x.p.Sale.HasValue ? x.p.Sale.Value : x.p.List, x.p.List)) .First()).Select(p => p.p).ToArray(); return(retVal); }
public PriceListAssignmentEvaluator(IPricelistRepository repository, IEvaluationPolicy[] policies, ICacheRepository cache) { _repository = repository; _policies = policies; _isEnabled = CatalogConfiguration.Instance.Cache.IsEnabled; _cache = new CacheHelper(cache); }
/// <summary> /// Initializes a new instance of the <see cref="CatalogItemDocumentCreator" /> class. /// </summary> /// <param name="catalogRepository">The catalog repository.</param> /// <param name="pricelistRepository">The pricelist repository.</param> /// <param name="catalogOutlinebuilder">The catalog outline builder.</param> /// <param name="reviewRepository"></param> /// <param name="cacheRepository">The cache repository.</param> public CatalogItemDocumentCreator(ICatalogRepository catalogRepository, IPricelistRepository pricelistRepository, ICatalogOutlineBuilder catalogOutlinebuilder, IReviewRepository reviewRepository, ICacheRepository cacheRepository) { ReviewRepository = reviewRepository; CatalogRepository = catalogRepository; PriceListRepository = pricelistRepository; CacheRepository = cacheRepository; OutlineBuilder = catalogOutlinebuilder; }
/// <summary> /// Initializes a new instance of the <see cref="PriceListClient" /> class. /// </summary> /// <param name="priceListRepository">The price list repository.</param> /// <param name="customerSession">The customer session.</param> /// <param name="priceListEvaluator">The price list evaluator.</param> /// <param name="priceListEvalContext">The price list eval context.</param> /// <param name="cacheRepository">The cache repository.</param> public PriceListClient(IPricelistRepository priceListRepository, ICustomerSessionService customerSession, IPriceListAssignmentEvaluator priceListEvaluator, IPriceListAssignmentEvaluationContext priceListEvalContext, ICacheRepository cacheRepository) { _cacheRepository = cacheRepository; _priceListRepository = priceListRepository; _customerSession = customerSession; _priceListEvalContext = priceListEvalContext; _priceListEvaluator = priceListEvaluator; _isEnabled = CatalogConfiguration.Instance.Cache.IsEnabled; }
/// <summary> /// Initializes a new instance of the <see cref="CatalogItemIndexBuilder" /> class. /// </summary> /// <param name="searchProvider">The search provider.</param> /// <param name="catalogRepository">The catalog repository.</param> /// <param name="priceListRepository">The price list repository.</param> /// <param name="logRepository">The log repository.</param> /// <param name="catalogOutlinebuilder">The catalog outlinebuilder.</param> /// <param name="reviewRepository">The review repository.</param> /// <param name="cacheRepository">The cache repository.</param> public CatalogItemIndexBuilder(ISearchProvider searchProvider, ICatalogRepository catalogRepository, IPricelistRepository priceListRepository, IOperationLogRepository logRepository, ICatalogOutlineBuilder catalogOutlinebuilder, IReviewRepository reviewRepository, ICacheRepository cacheRepository) { ReviewRepository = reviewRepository; CatalogRepository = catalogRepository; PriceListRepository = priceListRepository; SearchProvider = searchProvider; LogRepository = logRepository; OutlineBuilder = catalogOutlinebuilder; CacheRepository = cacheRepository; }
/// <summary> /// Gets the item prices. Works from DSClient. /// </summary> /// <param name="repository">The repository.</param> /// <param name="pricelistIds">The pricelist ids.</param> /// <param name="itemId">The item id.</param> /// <param name="quantity">The quantity.</param> /// <returns></returns> public static Price[] GetItemPrices(this IPricelistRepository repository, string[] pricelistIds, string itemId, decimal quantity) { var retVal = repository.Prices.Where(x => x.ItemId == itemId && quantity >= x.MinQuantity).ToArray(); if (pricelistIds != null) { pricelistIds = pricelistIds.Where(x => !String.IsNullOrEmpty(x)).ToArray(); if (pricelistIds.Any()) { retVal = retVal.Where(x => pricelistIds.Contains(x.PricelistId, StringComparer.OrdinalIgnoreCase)).ToArray(); } } return(retVal); }
public CalculateDiscountsActivity(ICatalogRepository catalogRepository, cust.ICustomerSessionService customerService, IMarketingRepository marketingRepository, IPricelistRepository priceListRepository, IPromotionEntryPopulate entryPopulate, ICatalogOutlineBuilder catalogOutlineBuilder, IPromotionEvaluator evaluator) { _catalogRepository = catalogRepository; _marketingRepository = marketingRepository; _promotionEntryPopulate = entryPopulate; _priceListRepository = priceListRepository; _customerSessionService = customerService; _catalogOutlineBuilder = catalogOutlineBuilder; _promotionEvaluator = evaluator; }
/// <summary> /// Initializes a new instance of the <see cref="ValidateLineItemsActivity"/> class. /// </summary> /// <param name="inventoryRepository">The inventory repository.</param> /// <param name="catalogRepository">The catalog repository.</param> /// <param name="storeRepository">The store repository.</param> /// <param name="customerService">The customer service.</param> /// <param name="priceListRepository">The price list repository.</param> /// <param name="currencyService">The currency service.</param> /// <param name="priceListEvaluator">The price list evaluator.</param> /// <param name="priceListEvalContext">The price list eval context.</param> /// <param name="cacheRepository">The cache repository.</param> public ValidateLineItemsActivity(IInventoryRepository inventoryRepository, ICatalogRepository catalogRepository, IStoreRepository storeRepository, ICustomerSessionService customerService, IPricelistRepository priceListRepository, ICurrencyService currencyService, IPriceListAssignmentEvaluator priceListEvaluator, IPriceListAssignmentEvaluationContext priceListEvalContext, ICacheRepository cacheRepository) { _inventoryRepository = inventoryRepository; _catalogRepository = catalogRepository; _storeRepository = storeRepository; _customerSessionService = customerService; _pricelistRepository = priceListRepository; _currencyService = currencyService; _priceListEvalContext = priceListEvalContext; _cacheRepository = cacheRepository; _priceListEvaluator = priceListEvaluator; }
public static Price FindLowestPriceDirect(this IPricelistRepository repository, string[] pricelistIds, string itemId, decimal quantity) { var lists = new List <dynamic>(); for (int index = 0; index < pricelistIds.Length; index++) { lists.Add(new { name = pricelistIds[index], order = index }); } // get all the prices var prices = repository.GetItemPrices(pricelistIds, itemId, quantity); // group and sort prices, returning lowest price found in the first price list examined for each item var retVal = (from p in prices join l in lists on p.PricelistId.ToLower() equals l.name.ToLower() select new { p, l.order }) .GroupBy(pl => pl.p.ItemId) .Select(p => p.OrderBy(pl => pl.order) .ThenBy(x => Math.Min(x.p.Sale.HasValue ? x.p.Sale.Value : x.p.List, x.p.List)) .First()).Select(p => p.p).FirstOrDefault(); return(retVal); }
public override string Import(string catalogId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _catalogRepository = (ICatalogRepository) repository; _repository = (IPricelistRepository) repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); var itemId = systemValues.First(y => y.Name == "ItemId").Value; var catName = systemValues.First(y => y.Name == "CatalogId").Value; if (!string.IsNullOrEmpty(catName)) catalogId = _catalogRepository.Catalogs.Where(cat => cat.Name == catName).First().CatalogId; //get item with the provided ItemId or item Code var originalItems = _catalogRepository.Items.Where(x => x.ItemId == itemId || x.Code == itemId).ToArray(); Item originalItem; //if more than 1 item found and catalogId is not provided - return error, otherwise ok if (originalItems.Count() > 1) { if (!string.IsNullOrEmpty(catalogId)) originalItem = originalItems.FirstOrDefault(x => x.CatalogId == catalogId); else { var catNames = string.Empty; originalItems.ToList().ForEach(x => catNames = catNames + x.CatalogId + ", "); _error = string.Format("Item with code - {0} has matches in catalogs: {1}. Specify catalog property.", itemId, catNames); return _error; } } else { originalItem = originalItems.FirstOrDefault(); } //if item with the code found (not null) try to execute the import action otherwise return error if (originalItem != null) { switch (action) { case ImportAction.Insert: var addItem = InitializeItem(null, systemValues); //set price itemId to the found ItemId addItem.ItemId = originalItem.ItemId; _repository.Add(addItem); break; case ImportAction.InsertAndReplace: var qtyR = systemValues.FirstOrDefault(y => y.Name == "MinQuantity"); var listIdR = systemValues.FirstOrDefault(y => y.Name == "PricelistId"); if (qtyR != null && listIdR != null) { var qtyVal = int.Parse(qtyR.Value); var origItem = _repository.Prices.ToList().Where(x => x.ItemId == originalItem.ItemId && x.MinQuantity == qtyVal && x.PricelistId == listIdR.Value).SingleOrDefault(); if (origItem != null) { InitializeItem(origItem, systemValues); //set price itemId to the found ItemId origItem.ItemId = originalItem.ItemId; _repository.Update(origItem); } else { var newItem = InitializeItem(null, systemValues); //set price itemId to the found ItemId newItem.ItemId = originalItem.ItemId; _repository.Add(newItem); } } break; case ImportAction.Update: var qty = systemValues.FirstOrDefault(y => y.Name == "MinQuantity"); var listId = systemValues.FirstOrDefault(y => y.Name == "PricelistId"); if (qty != null && listId != null) { var qtyVal = int.Parse(qty.Value); var origItem = _repository.Prices.ToList().Where(x => x.ItemId == originalItem.ItemId && x.MinQuantity == qtyVal && x.PricelistId == listId.Value).SingleOrDefault(); if (origItem != null) { InitializeItem(origItem, systemValues); //set price itemId to the found ItemId origItem.ItemId = originalItem.ItemId; _repository.Update(origItem); } } break; case ImportAction.Delete: var qtyValue = systemValues.FirstOrDefault(y => y.Name == "MinQuantity"); var pricelistId = systemValues.FirstOrDefault(y => y.Name == "PricelistId"); if (qtyValue != null && pricelistId != null) { var qtyVal = int.Parse(qtyValue.Value); var deleteItem = _repository.Prices.ToList().Where(x => x.ItemId == originalItem.ItemId && x.MinQuantity == qtyVal && x.PricelistId == pricelistId.Value).SingleOrDefault(); if (deleteItem != null) _repository.Remove(deleteItem); } break; } } else { _error = string.Format("Item with itemId/code - {0} not found", itemId); } return _error; }
public PricelistService(IPricelistRepository repository) : base(repository) { }
public static ReturnBuilder GetReturnBuilder(IOrderEntityFactory entityFactory, IPricelistRepository priceListRepository, Foundation.Orders.Model.Order order, RmaRequest rmaRequest, OrderClient client, IOrderService service) { if (entityFactory == null) { throw new ArgumentNullException("entityFactory"); } if (order == null) { throw new ArgumentNullException("order"); } var retVal = new ReturnBuilder(entityFactory, priceListRepository, client, service); retVal.WithOrderOrRmaRequest(order, rmaRequest); return(retVal); }
public override string Import(string catalogId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _catalogRepository = (ICatalogRepository)repository; _repository = (IPricelistRepository)repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); var itemId = systemValues.First(y => y.Name == "ItemId").Value; var catName = systemValues.First(y => y.Name == "CatalogId").Value; if (!string.IsNullOrEmpty(catName)) { catalogId = _catalogRepository.Catalogs.Where(cat => cat.Name == catName).First().CatalogId; } //get item with the provided ItemId or item Code var originalItems = _catalogRepository.Items.Where(x => x.ItemId == itemId || x.Code == itemId).ToArray(); Item originalItem; //if more than 1 item found and catalogId is not provided - return error, otherwise ok if (originalItems.Count() > 1) { if (!string.IsNullOrEmpty(catalogId)) { originalItem = originalItems.FirstOrDefault(x => x.CatalogId == catalogId); } else { var catNames = string.Empty; originalItems.ToList().ForEach(x => catNames = catNames + x.CatalogId + ", "); _error = string.Format("Item with code - {0} has matches in catalogs: {1}. Specify catalog property.", itemId, catNames); return(_error); } } else { originalItem = originalItems.FirstOrDefault(); } //if item with the code found (not null) try to execute the import action otherwise return error if (originalItem != null) { switch (action) { case ImportAction.Insert: var addItem = InitializeItem(null, systemValues); //set price itemId to the found ItemId addItem.ItemId = originalItem.ItemId; _repository.Add(addItem); break; case ImportAction.InsertAndReplace: var qtyR = systemValues.FirstOrDefault(y => y.Name == "MinQuantity"); var listIdR = systemValues.FirstOrDefault(y => y.Name == "PricelistId"); if (qtyR != null && listIdR != null) { var pricelist = _repository.Pricelists.Where(x => x.Name == listIdR.Value || x.PricelistId == listIdR.Value).FirstOrDefault(); var qtyVal = int.Parse(qtyR.Value); var origItem = _repository.Prices.ToList().Where(x => x.ItemId == originalItem.ItemId && x.MinQuantity == qtyVal && x.PricelistId == pricelist.PricelistId).SingleOrDefault(); if (origItem != null) { InitializeItem(origItem, systemValues); //set price itemId to the found ItemId origItem.ItemId = originalItem.ItemId; _repository.Update(origItem); } else { var newItem = InitializeItem(null, systemValues); //set price itemId to the found ItemId newItem.ItemId = originalItem.ItemId; _repository.Add(newItem); } } break; case ImportAction.Update: var qty = systemValues.FirstOrDefault(y => y.Name == "MinQuantity"); var listId = systemValues.FirstOrDefault(y => y.Name == "PricelistId"); if (qty != null && listId != null) { var pricelist = _repository.Pricelists.Where(x => x.Name == listId.Value || x.PricelistId == listId.Value).FirstOrDefault(); var qtyVal = int.Parse(qty.Value); var origItem = _repository.Prices.ToList().Where(x => x.ItemId == originalItem.ItemId && x.MinQuantity == qtyVal && x.PricelistId == pricelist.PricelistId).SingleOrDefault(); if (origItem != null) { InitializeItem(origItem, systemValues); //set price itemId to the found ItemId origItem.ItemId = originalItem.ItemId; _repository.Update(origItem); } } break; case ImportAction.Delete: var qtyValue = systemValues.FirstOrDefault(y => y.Name == "MinQuantity"); var pricelistId = systemValues.FirstOrDefault(y => y.Name == "PricelistId"); if (qtyValue != null && pricelistId != null) { var qtyVal = int.Parse(qtyValue.Value); var deleteItem = _repository.Prices.ToList().Where(x => x.ItemId == originalItem.ItemId && x.MinQuantity == qtyVal && x.PricelistId == pricelistId.Value).SingleOrDefault(); if (deleteItem != null) { _repository.Remove(deleteItem); } } break; } } else { _error = string.Format("Item with itemId/code - {0} not found", itemId); } return(_error); }