public IHttpActionResult EvaluatePrices(coreModel.PriceEvaluationContext evalContext) { var retVal = _pricingService.EvaluateProductPrices(evalContext) .Select(x => x.ToWebModel()) .ToArray(); return(Ok(retVal)); }
/// <summary> /// Search products by given criteria /// </summary> /// <param name="criteria"></param> /// <returns></returns> public CatalogSearchResult SearchProducts(CatalogSearchCriteria criteria) { var workContext = _workContextFactory(); criteria = criteria.Clone(); //exclude categories criteria.ResponseGroup = criteria.ResponseGroup & (~CatalogSearchResponseGroup.WithCategories); //include products criteria.ResponseGroup = criteria.ResponseGroup | CatalogSearchResponseGroup.WithProducts; var searchCriteria = criteria.ToServiceModel(workContext); var result = _searchApi.SearchModuleSearch(searchCriteria); var products = result.Products.Select(x => x.ToWebModel(workContext.CurrentLanguage, workContext.CurrentCurrency, workContext.CurrentStore)).ToList(); //Unable to make parallel call because its synchronous method (in future this information pricing and inventory will be getting from search index) and this lines can be removed _pricingService.EvaluateProductPrices(products); LoadProductsInventories(products); return(new CatalogSearchResult { Products = new StaticPagedList <Product>(products, criteria.PageNumber, criteria.PageSize, result.ProductsTotalCount.Value), Aggregations = !result.Aggregations.IsNullOrEmpty() ? result.Aggregations.Select(x => x.ToWebModel(workContext.CurrentLanguage.CultureName)).ToArray() : new Aggregation[] { } }); }
protected virtual IList <Price> GetItemPrices(string[] itemIds) { var evalContext = new PriceEvaluationContext { ProductIds = itemIds }; return(_pricingService.EvaluateProductPrices(evalContext).ToList()); }
protected virtual IList <Price> GetProductPrices(IList <string> productIds) { var evalContext = AbstractTypeFactory <PriceEvaluationContext> .TryCreateInstance(); evalContext.ProductIds = productIds.ToArray(); evalContext.CertainDate = DateTime.UtcNow; return(_pricingService.EvaluateProductPrices(evalContext).ToList()); }
public IHttpActionResult GetProductPrices(string productId) { var prices = _pricingService.EvaluateProductPrices(new coreModel.PriceEvaluationContext { ProductIds = new [] { productId } }); var result = prices != null ? prices.GroupBy(x => x.Currency).Select(x => x.First().ToWebModel()).ToArray() : null; return(result != null?Ok(result) : (IHttpActionResult)NotFound()); }
public IHttpActionResult GetProductPrices(string productId) { IHttpActionResult retVal = NotFound(); var prices = _pricingService.EvaluateProductPrices(new coreModel.PriceEvaluationContext { ProductIds = new string[] { productId } }); if (prices != null) { retVal = Ok(prices.GroupBy(x => x.Currency).Select(x => x.First().ToWebModel()).ToArray()); } return(retVal); }
public IEnumerable <Product> GetProductUpdates(IEnumerable <string> ids) { Collection <Product> retVal = null; var items = _itemService.GetByIds(ids.ToArray(), ItemResponseGroup.ItemLarge); items.ForEach(product => { var converted = product.ToGoogleModel(_assetUrlResolver); var prices = _pricingService.EvaluateProductPrices(new PriceEvaluationContext { ProductIds = new string[] { converted.Id } }); if (prices != null) { converted.Price = prices.First(x => x.Currency == "USD").ToGoogleModel(); if (retVal == null) { retVal = new Collection <Product>(); } retVal.Add(converted); } }); return(retVal); }
private bool TryGetProductPrice(string productId, out GooglePrice productPrice) { var prices = _pricingService.EvaluateProductPrices(new PriceEvaluationContext { ProductIds = new string[] { productId } }); if (prices == null) { productPrice = null; return(false); } productPrice = prices.First(x => x.Currency == "USD").ToGoogleModel(); return(true); }
protected virtual void IndexItemPrices(ref ResultDocument doc, CatalogProduct item) { var evalContext = new Domain.Pricing.Model.PriceEvaluationContext { ProductIds = new[] { item.Id } }; var prices = _pricingService.EvaluateProductPrices(evalContext); foreach (var price in prices) { //var priceList = price.Pricelist; doc.Add(new DocumentField(string.Format("price_{0}_{1}", price.Currency, price.PricelistId).ToLower(), price.EffectiveValue, new[] { IndexStore.No, IndexType.NotAnalyzed })); doc.Add(new DocumentField(string.Format("price_{0}_{1}_value", price.Currency, price.PricelistId).ToLower(), (price.EffectiveValue).ToString(CultureInfo.InvariantCulture), new[] { IndexStore.Yes, IndexType.NotAnalyzed })); } }
public IHttpActionResult GetProductPrices([FromUri] string[] priceLists, [FromUri] string[] products) { var retVal = new List <Price>(); var evalContext = new Domain.Pricing.Model.PriceEvaluationContext() { ProductIds = products, PricelistIds = priceLists }; var strProducts = priceLists != null?String.Join(":", priceLists) : string.Empty; var strPriceLists = products != null?String.Join(":", products) : string.Empty; var cacheKey = CacheKey.Create("MP", "GetProductPrices", strProducts, strPriceLists); var prices = _cacheManager.Get(cacheKey, () => _pricingService.EvaluateProductPrices(evalContext)); retVal.AddRange(prices.Select(x => x.ToWebModel())); return(Ok(retVal)); }
/// <summary> /// Search products by given criteria /// </summary> /// <param name="criteria"></param> /// <returns></returns> public virtual CatalogSearchResult SearchProducts(ProductSearchCriteria criteria) { criteria = criteria.Clone(); var workContext = _workContextFactory(); var searchCriteria = criteria.ToProductSearchDto(workContext); var result = _searchApi.SearchApiModule.SearchProducts(workContext.CurrentStore.Id, searchCriteria); var products = result.Products.Select(x => x.ToProduct(workContext.CurrentLanguage, workContext.CurrentCurrency, workContext.CurrentStore)).ToList(); if (products.Any()) { var productsWithVariations = products.Concat(products.SelectMany(x => x.Variations)).ToList(); //Unable to make parallel call because its synchronous method (in future this information pricing and inventory will be getting from search index) and this lines can be removed _pricingService.EvaluateProductPrices(productsWithVariations); LoadProductInventories(productsWithVariations); LoadProductVendors(productsWithVariations); } return(new CatalogSearchResult { Products = new StaticPagedList <Product>(products, criteria.PageNumber, criteria.PageSize, (int?)result.TotalCount ?? 0), Aggregations = !result.Aggregations.IsNullOrEmpty() ? result.Aggregations.Select(x => x.ToAggregation(workContext.CurrentLanguage.CultureName)).ToArray() : new Aggregation[] { } }); }
public IHttpActionResult EvaluatePrices(PriceEvaluationContext evalContext) { var retVal = _pricingService.EvaluateProductPrices(evalContext).ToArray(); return(Ok(retVal)); }
public IEnumerable <Price> EvaluateProductPrices(PriceEvaluationContext evalContext) { return(_pricingService.EvaluateProductPrices(evalContext)); }
public virtual void DoExport(string catalogId, string[] exportedCategories, string[] exportedProducts, string pricelistId, string fulfilmentCenterId, CurrencyCodes currency, string languageCode, ExportNotification notification) { var memoryStream = new MemoryStream(); var streamWriter = new StreamWriter(memoryStream); streamWriter.AutoFlush = true; var productPropertyInfos = typeof(CatalogProduct).GetProperties(BindingFlags.Instance | BindingFlags.Public); string catalogName = null; using (var csvWriter = new CsvWriter(streamWriter)) { csvWriter.Configuration.Delimiter = ";"; //Notification notification.Description = "loading products..."; _notifier.Upsert(notification); try { //Load all products to export var products = LoadProducts(catalogId, exportedCategories, exportedProducts); //Notification notification.Description = "loading prices..."; _notifier.Upsert(notification); var allProductIds = products.Select(x => x.Id).ToArray(); //Load prices for products var priceEvalContext = new PriceEvaluationContext { ProductIds = allProductIds, PricelistIds = pricelistId == null ? null : new string[] { pricelistId }, Currency = currency }; var allProductPrices = _pricingService.EvaluateProductPrices(priceEvalContext).ToArray(); foreach (var product in products) { product.Prices = allProductPrices.Where(x => x.ProductId == product.Id).ToList(); } //Load inventories notification.Description = "loading inventory information..."; _notifier.Upsert(notification); var allProductInventories = _inventoryService.GetProductsInventoryInfos(allProductIds); foreach (var product in products) { product.Inventories = allProductInventories.Where(x => x.ProductId == product.Id) .Where(x => fulfilmentCenterId == null ? true : x.FulfillmentCenterId == fulfilmentCenterId).ToList(); } notification.TotalCount = products.Count(); //populate export configuration Dictionary <string, Func <CatalogProduct, string> > exportConfiguration = new Dictionary <string, Func <CatalogProduct, string> >(); PopulateProductExportConfiguration(exportConfiguration, products); //Write header foreach (var cfgItem in exportConfiguration) { csvWriter.WriteField(cfgItem.Key); } csvWriter.NextRecord(); var notifyProductSizeLimit = 50; var counter = 0; //Write products foreach (var product in products) { if (catalogName == null && product.Catalog != null) { catalogName = product.Catalog.Name; } try { foreach (var cfgItem in exportConfiguration) { var fieldValue = String.Empty; if (cfgItem.Value == null) { var propertyInfo = productPropertyInfos.FirstOrDefault(x => x.Name == cfgItem.Key); if (propertyInfo != null) { var objValue = propertyInfo.GetValue(product); fieldValue = objValue != null?objValue.ToString() : fieldValue; } } else { fieldValue = cfgItem.Value(product); } csvWriter.WriteField(fieldValue); } csvWriter.NextRecord(); } catch (Exception ex) { notification.ErrorCount++; notification.Errors.Add(ex.ToString()); _notifier.Upsert(notification); } //Raise notification each notifyProductSizeLimit products counter++; notification.ProcessedCount = counter; notification.Description = string.Format("{0} of {1} products processed", notification.ProcessedCount, notification.TotalCount); if (counter % notifyProductSizeLimit == 0) { _notifier.Upsert(notification); } } memoryStream.Position = 0; //Upload result csv to blob storage var uploadInfo = new UploadStreamInfo { FileName = "Catalog-" + (catalogName ?? catalogId) + "-export.csv", FileByteStream = memoryStream, FolderName = "temp" }; var blobKey = _blobStorageProvider.Upload(uploadInfo); //Get a download url notification.DownloadUrl = _blobUrlResolver.GetAbsoluteUrl(blobKey); notification.Description = "Export finished"; } catch (Exception ex) { notification.Description = "Export error"; notification.ErrorCount++; notification.Errors.Add(ex.ToString()); } finally { notification.Finished = DateTime.UtcNow; _notifier.Upsert(notification); } } }
public void DoExport(Stream outStream, CsvExportInfo exportInfo, Action <ExportImportProgressInfo> progressCallback) { var prodgressInfo = new ExportImportProgressInfo { Description = "loading products..." }; var streamWriter = new StreamWriter(outStream, Encoding.UTF8, 1024, true) { AutoFlush = true }; using (var csvWriter = new CsvWriter(streamWriter)) { //Notification progressCallback(prodgressInfo); //Load all products to export var products = LoadProducts(exportInfo.CatalogId, exportInfo.CategoryIds, exportInfo.ProductIds); var allProductIds = products.Select(x => x.Id).ToArray(); //Load prices for products prodgressInfo.Description = "loading prices..."; progressCallback(prodgressInfo); var priceEvalContext = new PriceEvaluationContext { ProductIds = allProductIds, PricelistIds = exportInfo.PriceListId == null ? null : new[] { exportInfo.PriceListId }, Currency = exportInfo.Currency }; var allProductPrices = _pricingService.EvaluateProductPrices(priceEvalContext).ToList(); //Load inventories prodgressInfo.Description = "loading inventory information..."; progressCallback(prodgressInfo); var allProductInventories = _inventoryService.GetProductsInventoryInfos(allProductIds).Where(x => exportInfo.FulfilmentCenterId == null || x.FulfillmentCenterId == exportInfo.FulfilmentCenterId).ToList(); //Export configuration exportInfo.Configuration.PropertyCsvColumns = products.SelectMany(x => x.PropertyValues).Select(x => x.PropertyName).Distinct().ToArray(); csvWriter.Configuration.Delimiter = exportInfo.Configuration.Delimiter; csvWriter.Configuration.RegisterClassMap(new CsvProductMap(exportInfo.Configuration)); //Write header csvWriter.WriteHeader <CsvProduct>(); csvWriter.NextRecord(); prodgressInfo.TotalCount = products.Count; var notifyProductSizeLimit = 50; var counter = 0; //convert to dict for faster search var pricesDict = allProductPrices.GroupBy(x => x.ProductId).ToDictionary(x => x.Key, x => x.First()); var inventoriesDict = allProductInventories.GroupBy(x => x.ProductId).ToDictionary(x => x.Key, x => x.First()); foreach (var product in products) { try { var csvProducts = MakeMultipleExportProducts(product, pricesDict, inventoriesDict); csvWriter.WriteRecords(csvProducts); } catch (Exception ex) { prodgressInfo.Errors.Add(ex.ToString()); progressCallback(prodgressInfo); } //Raise notification each notifyProductSizeLimit products counter++; prodgressInfo.ProcessedCount = counter; prodgressInfo.Description = string.Format("{0} of {1} products processed", prodgressInfo.ProcessedCount, prodgressInfo.TotalCount); if (counter % notifyProductSizeLimit == 0 || counter == prodgressInfo.TotalCount) { progressCallback(prodgressInfo); } } } }