public async Task EvaluateProductPricesAsync(IEnumerable<Product> products) { var workContext = _workContextFactory(); //Evaluate products prices var evalContext = new VirtoCommerceDomainPricingModelPriceEvaluationContext { ProductIds = products.Select(p => p.Id).ToList(), PricelistIds = workContext.CurrentPricelists.Select(p => p.Id).ToList(), CatalogId = workContext.CurrentStore.Catalog, CustomerId = workContext.CurrentCustomer.Id, Language = workContext.CurrentLanguage.CultureName, CertainDate = workContext.StorefrontUtcNow, StoreId = workContext.CurrentStore.Id }; var pricesResponse = await _pricingApi.PricingModuleEvaluatePricesAsync(evalContext); var alreadyDefinedProductsPriceGroups = pricesResponse.Select(x => x.ToWebModel(workContext.AllCurrencies, workContext.CurrentLanguage)).GroupBy(x => x.ProductId); foreach (var product in products) { var productPricesGroup = alreadyDefinedProductsPriceGroups.FirstOrDefault(x => x.Key == product.Id); if (productPricesGroup != null) { //Get first price for each currency product.Prices = productPricesGroup.GroupBy(x => x.Currency).Select(x => x.FirstOrDefault()).Where(x => x != null).ToList(); } //Need add product price for all store currencies (even if not returned from api need make it by currency exchange convertation) foreach (var storeCurrency in workContext.CurrentStore.Currencies) { var price = product.Prices.FirstOrDefault(x => x.Currency == storeCurrency); if (price == null) { price = new ProductPrice(storeCurrency); if (product.Prices.Any()) { price = product.Prices.First().ConvertTo(storeCurrency); } product.Prices.Add(price); } } product.Currency = workContext.CurrentCurrency; product.Price = product.Prices.FirstOrDefault(x => x.Currency.Equals(workContext.CurrentCurrency)); } }
public async Task EvaluateProductPricesAsync(IEnumerable <Product> products) { var workContext = _workContextFactory(); //Evaluate products prices var evalContext = new VirtoCommerceDomainPricingModelPriceEvaluationContext { ProductIds = products.Select(p => p.Id).ToList(), PricelistIds = workContext.CurrentPricelists.Select(p => p.Id).ToList(), CatalogId = workContext.CurrentStore.Catalog, CustomerId = workContext.CurrentCustomer.Id, Language = workContext.CurrentLanguage.CultureName, CertainDate = workContext.StorefrontUtcNow, StoreId = workContext.CurrentStore.Id }; var pricesResponse = await _pricingApi.PricingModuleEvaluatePricesAsync(evalContext); var alreadyDefinedProductsPriceGroups = pricesResponse.Select(x => x.ToWebModel(workContext.AllCurrencies, workContext.CurrentLanguage)).GroupBy(x => x.ProductId); foreach (var product in products) { var productPricesGroup = alreadyDefinedProductsPriceGroups.FirstOrDefault(x => x.Key == product.Id); if (productPricesGroup != null) { //Get first price for each currency product.Prices = productPricesGroup.GroupBy(x => x.Currency).Select(x => x.FirstOrDefault()).Where(x => x != null).ToList(); } //Need add product price for all store currencies (even if not returned from api need make it by currency exchange convertation) foreach (var storeCurrency in workContext.CurrentStore.Currencies) { var price = product.Prices.FirstOrDefault(x => x.Currency == storeCurrency); if (price == null) { price = new ProductPrice(storeCurrency); if (product.Prices.Any()) { price = product.Prices.First().ConvertTo(storeCurrency); } product.Prices.Add(price); } } product.Currency = workContext.CurrentCurrency; product.Price = product.Prices.FirstOrDefault(x => x.Currency.Equals(workContext.CurrentCurrency)); } }
public static VirtoCommerceDomainPricingModelPriceEvaluationContext ToServiceModel(this IEnumerable<Product> products, WorkContext workContext) { if(products == null) { throw new ArgumentNullException("products"); } //Evaluate products prices var retVal = new VirtoCommerceDomainPricingModelPriceEvaluationContext { ProductIds = products.Select(p => p.Id).ToList(), PricelistIds = workContext.CurrentPricelists.Select(p => p.Id).ToList(), CatalogId = workContext.CurrentStore.Catalog, CustomerId = workContext.CurrentCustomer.Id, Language = workContext.CurrentLanguage.CultureName, CertainDate = workContext.StorefrontUtcNow, StoreId = workContext.CurrentStore.Id }; return retVal; }
public static VirtoCommerceDomainPricingModelPriceEvaluationContext ToServiceModel(this IEnumerable <Product> products, WorkContext workContext) { if (products == null) { throw new ArgumentNullException("products"); } //Evaluate products prices var retVal = new VirtoCommerceDomainPricingModelPriceEvaluationContext { ProductIds = products.Select(p => p.Id).ToList(), PricelistIds = workContext.CurrentPricelists.Select(p => p.Id).ToList(), CatalogId = workContext.CurrentStore.Catalog, CustomerId = workContext.CurrentCustomer.Id, Language = workContext.CurrentLanguage.CultureName, CertainDate = workContext.StorefrontUtcNow, StoreId = workContext.CurrentStore.Id }; return(retVal); }
public override async Task Invoke(IOwinContext context) { if (IsStorefrontRequest(context.Request)) { var workContext = _container.Resolve <WorkContext>(); var linkListService = _container.Resolve <IMenuLinkListService>(); var cartBuilder = _container.Resolve <ICartBuilder>(); var catalogSearchService = _container.Resolve <ICatalogSearchService>(); // Initialize common properties workContext.RequestUrl = context.Request.Uri; workContext.AllCountries = _allCountries; workContext.AllStores = await _cacheManager.GetAsync("GetAllStores", "ApiRegion", async() => await GetAllStoresAsync()); if (workContext.AllStores != null && workContext.AllStores.Any()) { // Initialize request specific properties workContext.CurrentStore = GetStore(context, workContext.AllStores); workContext.CurrentLanguage = GetLanguage(context, workContext.AllStores, workContext.CurrentStore); workContext.AllCurrencies = await _cacheManager.GetAsync("GetAllCurrencies-" + workContext.CurrentLanguage.CultureName, "ApiRegion", async() => { return((await _commerceApi.CommerceGetAllCurrenciesAsync()).Select(x => x.ToWebModel(workContext.CurrentLanguage)).ToArray()); }); //Sync store currencies with avail in system foreach (var store in workContext.AllStores) { store.SyncCurrencies(workContext.AllCurrencies, workContext.CurrentLanguage); store.CurrentSeoInfo = store.SeoInfos.FirstOrDefault(x => x.Language == workContext.CurrentLanguage); } //Set current currency workContext.CurrentCurrency = GetCurrency(context, workContext.CurrentStore); var qs = HttpUtility.ParseQueryString(workContext.RequestUrl.Query); //Initialize catalog search criteria workContext.CurrentCatalogSearchCriteria = new CatalogSearchCriteria(workContext.CurrentLanguage, workContext.CurrentCurrency, qs) { CatalogId = workContext.CurrentStore.Catalog }; //This line make delay categories loading initialization (categories can be evaluated on view rendering time) workContext.Categories = new MutablePagedList <Category>((pageNumber, pageSize) => { var criteria = workContext.CurrentCatalogSearchCriteria.Clone(); criteria.PageNumber = pageNumber; criteria.PageSize = pageSize; var result = catalogSearchService.SearchCategories(criteria); foreach (var category in result) { category.Products = new MutablePagedList <Product>((pageNumber2, pageSize2) => { criteria.CategoryId = category.Id; criteria.PageNumber = pageNumber2; criteria.PageSize = pageSize2; var searchResult = catalogSearchService.SearchProducts(criteria); //Because catalog search products returns also aggregations we can use it to populate workContext using C# closure //now workContext.Aggregation will be contains preloaded aggregations for current category workContext.Aggregations = new MutablePagedList <Aggregation>(searchResult.Aggregations); return(searchResult.Products); }); } return(result); }); //This line make delay products loading initialization (products can be evaluated on view rendering time) workContext.Products = new MutablePagedList <Product>((pageNumber, pageSize) => { var criteria = workContext.CurrentCatalogSearchCriteria.Clone(); criteria.PageNumber = pageNumber; criteria.PageSize = pageSize; var result = catalogSearchService.SearchProducts(criteria); //Prevent double api request for get aggregations //Because catalog search products returns also aggregations we can use it to populate workContext using C# closure //now workContext.Aggregation will be contains preloaded aggregations for current search criteria workContext.Aggregations = new MutablePagedList <Aggregation>(result.Aggregations); return(result.Products); }); //This line make delay aggregation loading initialization (aggregation can be evaluated on view rendering time) workContext.Aggregations = new MutablePagedList <Aggregation>((pageNumber, pageSize) => { var criteria = workContext.CurrentCatalogSearchCriteria.Clone(); criteria.PageNumber = pageNumber; criteria.PageSize = pageSize; //Force to load products and its also populate workContext.Aggregations by preloaded values workContext.Products.Slice(pageNumber, pageSize); return(workContext.Aggregations); }); workContext.CurrentOrderSearchCriteria = new Model.Order.OrderSearchCriteria(qs); workContext.CurrentQuoteSearchCriteria = new Model.Quote.QuoteSearchCriteria(qs); //Get current customer workContext.CurrentCustomer = await GetCustomerAsync(context); //Validate that current customer has to store access ValidateUserStoreLogin(context, workContext.CurrentCustomer, workContext.CurrentStore); MaintainAnonymousCustomerCookie(context, workContext); // Gets the collection of external login providers var externalAuthTypes = context.Authentication.GetExternalAuthenticationTypes(); workContext.ExternalLoginProviders = externalAuthTypes.Select(at => new LoginProvider { AuthenticationType = at.AuthenticationType, Caption = at.Caption, Properties = at.Properties }).ToList(); workContext.ApplicationSettings = GetApplicationSettings(); //Do not load shopping cart and other for resource requests if (!IsAssetRequest(context.Request)) { //Shopping cart await cartBuilder.GetOrCreateNewTransientCartAsync(workContext.CurrentStore, workContext.CurrentCustomer, workContext.CurrentLanguage, workContext.CurrentCurrency); workContext.CurrentCart = cartBuilder.Cart; if (workContext.CurrentStore.QuotesEnabled) { await _quoteRequestBuilder.GetOrCreateNewTransientQuoteRequestAsync(workContext.CurrentStore, workContext.CurrentCustomer, workContext.CurrentLanguage, workContext.CurrentCurrency); workContext.CurrentQuoteRequest = _quoteRequestBuilder.QuoteRequest; } var linkLists = await _cacheManager.GetAsync("GetAllStoreLinkLists-" + workContext.CurrentStore.Id, "ApiRegion", async() => await linkListService.LoadAllStoreLinkListsAsync(workContext.CurrentStore.Id)); workContext.CurrentLinkLists = linkLists.Where(x => x.Language == workContext.CurrentLanguage).ToList(); // load all static content var staticContents = _cacheManager.Get(string.Join(":", "AllStoreStaticContent", workContext.CurrentStore.Id), "ContentRegion", () => { var allContentItems = _staticContentService.LoadStoreStaticContent(workContext.CurrentStore).ToList(); var blogs = allContentItems.OfType <Blog>().ToArray(); var blogArticlesGroup = allContentItems.OfType <BlogArticle>().GroupBy(x => x.BlogName, x => x).ToList(); foreach (var blog in blogs) { var blogArticles = blogArticlesGroup.FirstOrDefault(x => string.Equals(x.Key, blog.Name, StringComparison.OrdinalIgnoreCase)); if (blogArticles != null) { blog.Articles = new MutablePagedList <BlogArticle>(blogArticles); } } return(new { Pages = allContentItems, Blogs = blogs }); }); workContext.Pages = new MutablePagedList <ContentItem>(staticContents.Pages); workContext.Blogs = new MutablePagedList <Blog>(staticContents.Blogs); // Initialize blogs search criteria workContext.CurrentBlogSearchCritera = new BlogSearchCriteria(qs); //Pricelists var pricelistCacheKey = string.Join("-", "EvaluatePriceLists", workContext.CurrentStore.Id, workContext.CurrentCustomer.Id); workContext.CurrentPricelists = await _cacheManager.GetAsync(pricelistCacheKey, "ApiRegion", async() => { var evalContext = new VirtoCommerceDomainPricingModelPriceEvaluationContext { StoreId = workContext.CurrentStore.Id, CatalogId = workContext.CurrentStore.Catalog, CustomerId = workContext.CurrentCustomer.Id, Quantity = 1 }; var pricingResult = await _pricingModuleApi.PricingModuleEvaluatePriceListsAsync(evalContext); return(pricingResult.Select(p => p.ToWebModel()).ToList()); }); } } } await Next.Invoke(context); }
public override async Task Invoke(IOwinContext context) { if (IsStorefrontRequest(context.Request)) { var workContext = _container.Resolve<WorkContext>(); var urlBuilder = _container.Resolve<IStorefrontUrlBuilder>(); var linkListService = _container.Resolve<IMenuLinkListService>(); var cartBuilder = _container.Resolve<ICartBuilder>(); var catalogSearchService = _container.Resolve<ICatalogSearchService>(); // Initialize common properties workContext.RequestUrl = context.Request.Uri; workContext.AllCountries = _allCountries; workContext.AllStores = await _cacheManager.GetAsync("GetAllStores", "ApiRegion", async () => { return await GetAllStoresAsync(); }); if (workContext.AllStores != null && workContext.AllStores.Any()) { // Initialize request specific properties workContext.CurrentStore = GetStore(context, workContext.AllStores); workContext.CurrentLanguage = GetLanguage(context, workContext.AllStores, workContext.CurrentStore); workContext.AllCurrencies = await _cacheManager.GetAsync("GetAllCurrencies-" + workContext.CurrentLanguage.CultureName, "ApiRegion", async () => { return (await _commerceApi.CommerceGetAllCurrenciesAsync()).Select(x => x.ToWebModel(workContext.CurrentLanguage)).ToArray(); }); //Sync store currencies with avail in system foreach (var store in workContext.AllStores) { store.SyncCurrencies(workContext.AllCurrencies, workContext.CurrentLanguage); store.CurrentSeoInfo = store.SeoInfos.FirstOrDefault(x => x.Language == workContext.CurrentLanguage); } //Set current currency workContext.CurrentCurrency = GetCurrency(context, workContext.CurrentStore); var qs = HttpUtility.ParseQueryString(workContext.RequestUrl.Query); //Initialize catalog search criteria workContext.CurrentCatalogSearchCriteria = new CatalogSearchCriteria(workContext.CurrentLanguage, workContext.CurrentCurrency, qs); workContext.CurrentCatalogSearchCriteria.CatalogId = workContext.CurrentStore.Catalog; //This line make delay categories loading initialization (categories can be evaluated on view rendering time) workContext.Categories = new MutablePagedList<Category>((pageNumber, pageSize) => { var criteria = workContext.CurrentCatalogSearchCriteria.Clone(); criteria.PageNumber = pageNumber; criteria.PageSize = pageSize; var result = catalogSearchService.SearchCategories(criteria); foreach (var category in result) { category.Products = new MutablePagedList<Product>((pageNumber2, pageSize2) => { criteria.CategoryId = category.Id; criteria.PageNumber = pageNumber2; criteria.PageSize = pageSize2; var searchResult = catalogSearchService.SearchProducts(criteria); //Because catalog search products returns also aggregations we can use it to populate workContext using C# closure //now workContext.Aggregation will be contains preloaded aggregations for current category workContext.Aggregations = new MutablePagedList<Aggregation>(searchResult.Aggregations, 1, int.MaxValue); return searchResult.Products; }); } return result; }); //This line make delay products loading initialization (products can be evaluated on view rendering time) workContext.Products = new MutablePagedList<Product>((pageNumber, pageSize) => { var criteria = workContext.CurrentCatalogSearchCriteria.Clone(); criteria.PageNumber = pageNumber; criteria.PageSize = pageSize; var result = catalogSearchService.SearchProducts(criteria); //Prevent double api request for get aggregations //Because catalog search products returns also aggregations we can use it to populate workContext using C# closure //now workContext.Aggregation will be contains preloaded aggregations for current search criteria workContext.Aggregations = new MutablePagedList<Aggregation>(result.Aggregations, 1, int.MaxValue); return result.Products; }); //This line make delay aggregation loading initialization (aggregation can be evaluated on view rendering time) workContext.Aggregations = new MutablePagedList<Aggregation>((pageNumber, pageSize) => { var criteria = workContext.CurrentCatalogSearchCriteria.Clone(); criteria.PageNumber = pageNumber; criteria.PageSize = pageSize; //Force to load products and its also populate workContext.Aggregations by preloaded values workContext.Products.Slice(pageNumber, pageSize); return workContext.Aggregations; }); workContext.CurrentOrderSearchCriteria = new Model.Order.OrderSearchCriteria(qs); workContext.CurrentQuoteSearchCriteria = new Model.Quote.QuoteSearchCriteria(qs); //Get current customer workContext.CurrentCustomer = await GetCustomerAsync(context); //Validate that current customer has to store access ValidateUserStoreLogin(context, workContext.CurrentCustomer, workContext.CurrentStore); MaintainAnonymousCustomerCookie(context, workContext); // Gets the collection of external login providers var externalAuthTypes = context.Authentication.GetExternalAuthenticationTypes(); workContext.ExternalLoginProviders = externalAuthTypes.Select(at => new LoginProvider { AuthenticationType = at.AuthenticationType, Caption = at.Caption, Properties = at.Properties }).ToList(); //Do not load shopping cart and other for resource requests if (!IsAssetRequest(context.Request)) { //Shopping cart await cartBuilder.GetOrCreateNewTransientCartAsync(workContext.CurrentStore, workContext.CurrentCustomer, workContext.CurrentLanguage, workContext.CurrentCurrency); workContext.CurrentCart = cartBuilder.Cart; if (workContext.CurrentStore.QuotesEnabled) { await _quoteRequestBuilder.GetOrCreateNewTransientQuoteRequestAsync(workContext.CurrentStore, workContext.CurrentCustomer, workContext.CurrentLanguage, workContext.CurrentCurrency); workContext.CurrentQuoteRequest = _quoteRequestBuilder.QuoteRequest; } var linkLists = await _cacheManager.GetAsync("GetAllStoreLinkLists-" + workContext.CurrentStore.Id, "ApiRegion", async () => await linkListService.LoadAllStoreLinkListsAsync(workContext.CurrentStore.Id)); workContext.CurrentLinkLists = linkLists.Where(x => x.Language == workContext.CurrentLanguage).ToList(); // load all static content var staticContents = _cacheManager.Get(string.Join(":", "AllStoreStaticContent", workContext.CurrentStore.Id), "ContentRegion", () => { var allContentItems = _staticContentService.LoadStoreStaticContent(workContext.CurrentStore); var blogs = allContentItems.OfType<Blog>().ToArray(); var blogArticlesGroup = allContentItems.OfType<BlogArticle>().GroupBy(x => x.BlogName, x => x); foreach (var blog in blogs) { var blogArticles = blogArticlesGroup.FirstOrDefault(x => string.Equals(x.Key, blog.Name, StringComparison.OrdinalIgnoreCase)); if (blogArticles != null) { blog.Articles = new MutablePagedList<BlogArticle>(blogArticles); } } return new { Pages = allContentItems, Blogs = blogs }; }); workContext.Pages = new MutablePagedList<ContentItem>(staticContents.Pages); workContext.Blogs = new MutablePagedList<Blog>(staticContents.Blogs); //Initialize blogs search criteria //TODO: read from query string workContext.CurrentBlogSearchCritera = new Model.StaticContent.BlogSearchCriteria(qs); //Pricelists var pricelistCacheKey = string.Join("-", "EvaluatePriceLists", workContext.CurrentStore.Id, workContext.CurrentCustomer.Id); workContext.CurrentPricelists = await _cacheManager.GetAsync(pricelistCacheKey, "ApiRegion", async () => { var evalContext = new VirtoCommerceDomainPricingModelPriceEvaluationContext { StoreId = workContext.CurrentStore.Id, CatalogId = workContext.CurrentStore.Catalog, CustomerId = workContext.CurrentCustomer.Id, Quantity = 1 }; var pricingResult = await _pricingModuleApi.PricingModuleEvaluatePriceListsAsync(evalContext); return pricingResult.Select(p => p.ToWebModel()).ToList(); }); } } } await Next.Invoke(context); }
/// <summary> /// Evaluate prices by given context /// </summary> /// <exception cref="VirtoCommerce.Client.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="evalContext">Pricing evaluation context</param> /// <returns>Task of ApiResponse (List<VirtoCommercePricingModuleWebModelPrice>)</returns> public async System.Threading.Tasks.Task<ApiResponse<List<VirtoCommercePricingModuleWebModelPrice>>> PricingModuleEvaluatePricesAsyncWithHttpInfo (VirtoCommerceDomainPricingModelPriceEvaluationContext evalContext) { // verify the required parameter 'evalContext' is set if (evalContext == null) throw new ApiException(400, "Missing required parameter 'evalContext' when calling PricingModuleApi->PricingModuleEvaluatePrices"); var localVarPath = "/api/pricing/evaluate"; var localVarPathParams = new Dictionary<String, String>(); var localVarQueryParams = new Dictionary<String, String>(); var localVarHeaderParams = new Dictionary<String, String>(Configuration.DefaultHeader); var localVarFormParams = new Dictionary<String, String>(); var localVarFileParams = new Dictionary<String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { "application/json", "text/json", "application/xml", "text/xml", "application/x-www-form-urlencoded" }; String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json", "text/json", "application/xml", "text/xml" }; String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); // set "format" to json by default // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json localVarPathParams.Add("format", "json"); if (evalContext.GetType() != typeof(byte[])) { localVarPostBody = Configuration.ApiClient.Serialize(evalContext); // http body (model) parameter } else { localVarPostBody = evalContext; // byte array } // make the HTTP request IRestResponse localVarResponse = (IRestResponse) await Configuration.ApiClient.CallApiAsync(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int) localVarResponse.StatusCode; if (localVarStatusCode >= 400 && (localVarStatusCode != 404 || Configuration.ThrowExceptionWhenStatusCodeIs404)) throw new ApiException (localVarStatusCode, "Error calling PricingModuleEvaluatePrices: " + localVarResponse.Content, localVarResponse.Content); else if (localVarStatusCode == 0) throw new ApiException (localVarStatusCode, "Error calling PricingModuleEvaluatePrices: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); return new ApiResponse<List<VirtoCommercePricingModuleWebModelPrice>>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (List<VirtoCommercePricingModuleWebModelPrice>) Configuration.ApiClient.Deserialize(localVarResponse, typeof(List<VirtoCommercePricingModuleWebModelPrice>))); }
/// <summary> /// Evaluate prices by given context /// </summary> /// <exception cref="VirtoCommerce.Client.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="evalContext">Pricing evaluation context</param> /// <returns>Task of List<VirtoCommercePricingModuleWebModelPrice></returns> public async System.Threading.Tasks.Task<List<VirtoCommercePricingModuleWebModelPrice>> PricingModuleEvaluatePricesAsync (VirtoCommerceDomainPricingModelPriceEvaluationContext evalContext) { ApiResponse<List<VirtoCommercePricingModuleWebModelPrice>> localVarResponse = await PricingModuleEvaluatePricesAsyncWithHttpInfo(evalContext); return localVarResponse.Data; }
/// <summary> /// Evaluate prices by given context /// </summary> /// <exception cref="VirtoCommerce.Client.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="evalContext">Pricing evaluation context</param> /// <returns>List<VirtoCommercePricingModuleWebModelPrice></returns> public List<VirtoCommercePricingModuleWebModelPrice> PricingModuleEvaluatePrices (VirtoCommerceDomainPricingModelPriceEvaluationContext evalContext) { ApiResponse<List<VirtoCommercePricingModuleWebModelPrice>> localVarResponse = PricingModuleEvaluatePricesWithHttpInfo(evalContext); return localVarResponse.Data; }
public override async Task Invoke(IOwinContext context) { if (IsStorefrontRequest(context.Request)) { var workContext = _container.Resolve <WorkContext>(); var urlBuilder = _container.Resolve <IStorefrontUrlBuilder>(); var linkListService = _container.Resolve <IMenuLinkListService>(); var cartBuilder = _container.Resolve <ICartBuilder>(); // Initialize common properties workContext.RequestUrl = context.Request.Uri; workContext.AllCountries = _allCountries; workContext.AllStores = await _cacheManager.GetAsync("GetAllStores", "ApiRegion", async() => { return(await GetAllStoresAsync()); }); if (workContext.AllStores != null && workContext.AllStores.Any()) { // Initialize request specific properties workContext.CurrentStore = GetStore(context, workContext.AllStores); workContext.CurrentLanguage = GetLanguage(context, workContext.AllStores, workContext.CurrentStore); workContext.AllCurrencies = await _cacheManager.GetAsync("GetAllCurrencies-" + workContext.CurrentLanguage.CultureName, "ApiRegion", async() => { return((await _commerceApi.CommerceGetAllCurrenciesAsync()).Select(x => x.ToWebModel(workContext.CurrentLanguage)).ToArray()); }); //Sync store currencies with avail in system foreach (var store in workContext.AllStores) { store.SyncCurrencies(workContext.AllCurrencies, workContext.CurrentLanguage); store.CurrentSeoInfo = store.SeoInfos.FirstOrDefault(x => x.Language == workContext.CurrentLanguage); } //Set current currency workContext.CurrentCurrency = GetCurrency(context, workContext.CurrentStore); var qs = HttpUtility.ParseQueryString(workContext.RequestUrl.Query); //Initialize catalog search criteria workContext.CurrentCatalogSearchCriteria = new CatalogSearchCriteria(qs); workContext.CurrentCatalogSearchCriteria.CatalogId = workContext.CurrentStore.Catalog; workContext.CurrentCatalogSearchCriteria.Currency = workContext.CurrentCurrency; workContext.CurrentCatalogSearchCriteria.Language = workContext.CurrentLanguage; workContext.CurrentOrderSearchCriteria = new Model.Order.OrderSearchCriteria(qs); workContext.CurrentQuoteSearchCriteria = new Model.Quote.QuoteSearchCriteria(qs); //Get current customer workContext.CurrentCustomer = await GetCustomerAsync(context); //Validate that current customer has to store access ValidateUserStoreLogin(context, workContext.CurrentCustomer, workContext.CurrentStore); MaintainAnonymousCustomerCookie(context, workContext); //Do not load shopping cart and other for resource requests if (!IsAssetRequest(context.Request)) { //Shopping cart await cartBuilder.GetOrCreateNewTransientCartAsync(workContext.CurrentStore, workContext.CurrentCustomer, workContext.CurrentLanguage, workContext.CurrentCurrency); workContext.CurrentCart = cartBuilder.Cart; if (workContext.CurrentStore.QuotesEnabled) { await _quoteRequestBuilder.GetOrCreateNewTransientQuoteRequestAsync(workContext.CurrentStore, workContext.CurrentCustomer, workContext.CurrentLanguage, workContext.CurrentCurrency); workContext.CurrentQuoteRequest = _quoteRequestBuilder.QuoteRequest; } var linkLists = await _cacheManager.GetAsync("GetAllStoreLinkLists-" + workContext.CurrentStore.Id, "ApiRegion", async() => await linkListService.LoadAllStoreLinkListsAsync(workContext.CurrentStore.Id)); workContext.CurrentLinkLists = linkLists.Where(x => x.Language == workContext.CurrentLanguage).ToList(); //Initialize blogs search criteria //TODO: read from query string workContext.CurrentBlogSearchCritera = new Model.StaticContent.BlogSearchCriteria(qs); //Pricelists var pricelistCacheKey = string.Join("-", "EvaluatePriceLists", workContext.CurrentStore.Id, workContext.CurrentCustomer.Id); workContext.CurrentPricelists = await _cacheManager.GetAsync(pricelistCacheKey, "ApiRegion", async() => { var evalContext = new VirtoCommerceDomainPricingModelPriceEvaluationContext { StoreId = workContext.CurrentStore.Id, CatalogId = workContext.CurrentStore.Catalog, CustomerId = workContext.CurrentCustomer.Id, Quantity = 1 }; var pricingResult = await _pricingModuleApi.PricingModuleEvaluatePriceListsAsync(evalContext); return(pricingResult.Select(p => p.ToWebModel()).ToList()); }); } } } await Next.Invoke(context); }
public override async Task Invoke(IOwinContext context) { if (IsStorefrontRequest(context.Request)) { var workContext = _container.Resolve<WorkContext>(); var urlBuilder = _container.Resolve<IStorefrontUrlBuilder>(); // Initialize common properties workContext.RequestUrl = context.Request.Uri; workContext.AllCountries = _allCountries; workContext.AllStores = await _cacheManager.GetAsync("GetAllStores", "ApiRegion", async () => { return await GetAllStoresAsync(); }); if (workContext.AllStores != null && workContext.AllStores.Any()) { // Initialize request specific properties workContext.CurrentStore = GetStore(context, workContext.AllStores); workContext.CurrentLanguage = GetLanguage(context, workContext.AllStores, workContext.CurrentStore); workContext.AllCurrencies = await _cacheManager.GetAsync("GetAllCurrencies-" + workContext.CurrentLanguage.CultureName, "ApiRegion", async () => { return (await _commerceApi.CommerceGetAllCurrenciesAsync()).Select(x => x.ToWebModel(workContext.CurrentLanguage)).ToArray(); }); //Sync store currencies with avail in system foreach (var store in workContext.AllStores) { store.SyncCurrencies(workContext.AllCurrencies, workContext.CurrentLanguage); store.CurrentSeoInfo = store.SeoInfos.FirstOrDefault(x => x.Language == workContext.CurrentLanguage); } //Set current currency workContext.CurrentCurrency = GetCurrency(context, workContext.CurrentStore); var qs = HttpUtility.ParseQueryString(workContext.RequestUrl.Query); //Initialize catalog search criteria workContext.CurrentCatalogSearchCriteria = new CatalogSearchCriteria(qs); workContext.CurrentCatalogSearchCriteria.CatalogId = workContext.CurrentStore.Catalog; workContext.CurrentCatalogSearchCriteria.Currency = workContext.CurrentCurrency; workContext.CurrentCatalogSearchCriteria.Language = workContext.CurrentLanguage; workContext.CurrentOrderSearchCriteria = new Model.Order.OrderSearchCriteria(qs); workContext.CurrentQuoteSearchCriteria = new Model.Quote.QuoteSearchCriteria(qs); //Current customer workContext.CurrentCustomer = await GetCustomerAsync(context); MaintainAnonymousCustomerCookie(context, workContext); //Do not load shopping cart and other for resource requests if (!IsAssetRequest(context.Request.Uri)) { //Shopping cart await _cartBuilder.GetOrCreateNewTransientCartAsync(workContext.CurrentStore, workContext.CurrentCustomer, workContext.CurrentLanguage, workContext.CurrentCurrency); workContext.CurrentCart = _cartBuilder.Cart; if (workContext.CurrentStore.QuotesEnabled) { await _quoteRequestBuilder.GetOrCreateNewTransientQuoteRequestAsync(workContext.CurrentStore, workContext.CurrentCustomer, workContext.CurrentLanguage, workContext.CurrentCurrency); workContext.CurrentQuoteRequest = _quoteRequestBuilder.QuoteRequest; } var linkLists = await _cacheManager.GetAsync("GetLinkLists-" + workContext.CurrentStore.Id, "ApiRegion", async () => { return await _cmsApi.MenuGetListsAsync(workContext.CurrentStore.Id) ?? new List<VirtoCommerceContentWebModelsMenuLinkList>(); }); workContext.CurrentLinkLists = linkLists != null ? linkLists.Select(ll => ll.ToWebModel(urlBuilder)).ToList() : null; //Initialize blogs search criteria //TODO: read from query string workContext.CurrentBlogSearchCritera = new Model.StaticContent.BlogSearchCriteria(qs); //Pricelists var pricelistCacheKey = string.Join("-", "EvaluatePriceLists", workContext.CurrentStore.Id, workContext.CurrentCustomer.Id); workContext.CurrentPricelists = await _cacheManager.GetAsync(pricelistCacheKey, "ApiRegion", async () => { var evalContext = new VirtoCommerceDomainPricingModelPriceEvaluationContext { StoreId = workContext.CurrentStore.Id, CatalogId = workContext.CurrentStore.Catalog, CustomerId = workContext.CurrentCustomer.Id, Quantity = 1 }; var pricingResult = await _pricingModuleApi.PricingModuleEvaluatePriceListsAsync(evalContext); return pricingResult.Select(p => p.ToWebModel()).ToList(); }); } } } await Next.Invoke(context); }
/// <summary> /// Evaluate pricelists by given context /// </summary> /// <param name="evalContext">Pricing evaluation context</param> /// <returns>Task of ApiResponse (List<VirtoCommercePricingModuleWebModelPricelist>)</returns> public async System.Threading.Tasks.Task<ApiResponse<List<VirtoCommercePricingModuleWebModelPricelist>>> PricingModuleEvaluatePriceListsAsyncWithHttpInfo (VirtoCommerceDomainPricingModelPriceEvaluationContext evalContext) { // verify the required parameter 'evalContext' is set if (evalContext == null) throw new ApiException(400, "Missing required parameter 'evalContext' when calling PricingModuleEvaluatePriceLists"); var path_ = "/api/pricing/pricelists/evaluate"; var pathParams = new Dictionary<String, String>(); var queryParams = new Dictionary<String, String>(); var headerParams = new Dictionary<String, String>(); var formParams = new Dictionary<String, String>(); var fileParams = new Dictionary<String, FileParameter>(); String postBody = null; // to determine the Accept header String[] http_header_accepts = new String[] { "application/json", "text/json" }; String http_header_accept = Configuration.ApiClient.SelectHeaderAccept(http_header_accepts); if (http_header_accept != null) headerParams.Add("Accept", Configuration.ApiClient.SelectHeaderAccept(http_header_accepts)); // set "format" to json by default // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json pathParams.Add("format", "json"); postBody = Configuration.ApiClient.Serialize(evalContext); // http body (model) parameter // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams); int statusCode = (int) response.StatusCode; if (statusCode >= 400) throw new ApiException (statusCode, "Error calling PricingModuleEvaluatePriceLists: " + response.Content, response.Content); else if (statusCode == 0) throw new ApiException (statusCode, "Error calling PricingModuleEvaluatePriceLists: " + response.ErrorMessage, response.ErrorMessage); return new ApiResponse<List<VirtoCommercePricingModuleWebModelPricelist>>(statusCode, response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (List<VirtoCommercePricingModuleWebModelPricelist>) Configuration.ApiClient.Deserialize(response, typeof(List<VirtoCommercePricingModuleWebModelPricelist>))); }
/// <summary> /// Evaluate pricelists by given context /// </summary> /// <param name="evalContext">Pricing evaluation context</param> /// <returns>List<VirtoCommercePricingModuleWebModelPricelist></returns> public List<VirtoCommercePricingModuleWebModelPricelist> PricingModuleEvaluatePriceLists (VirtoCommerceDomainPricingModelPriceEvaluationContext evalContext) { ApiResponse<List<VirtoCommercePricingModuleWebModelPricelist>> response = PricingModuleEvaluatePriceListsWithHttpInfo(evalContext); return response.Data; }