private void LoadProductVendors(List <Product> products) { var vendorIds = products.Where(p => !string.IsNullOrEmpty(p.VendorId)).Select(p => p.VendorId).Distinct().ToList(); var vendors = vendorIds.Select(id => _customerService.GetVendorById(id)).ToList(); foreach (var product in products) { product.Vendor = vendors.FirstOrDefault(v => v.Id == product.VendorId); if (product.Vendor != null) { product.Vendor.Products = new MutablePagedList <Product>((pageNumber, pageSize, sortInfos) => { var workContext = _workContextFactory(); var criteria = new CatalogSearchCriteria { CatalogId = workContext.CurrentStore.Catalog, SearchInChildren = true, PageNumber = pageNumber, PageSize = pageSize, SortBy = SortInfo.ToString(sortInfos), ResponseGroup = CatalogSearchResponseGroup.WithProducts }; var searchResult = SearchProducts(criteria); return(searchResult.Products); }); } } }
public async Task <CatalogSearchResult> SearchCatalogsAsync(CatalogSearchCriteria criteria) { var result = AbstractTypeFactory <CatalogSearchResult> .TryCreateInstance(); using (var repository = _catalogRepositoryFactory()) { //Optimize performance and CPU usage repository.DisableChangesTracking(); var sortInfos = BuildSortExpression(criteria); var query = BuildQuery(repository, criteria); result.TotalCount = await query.CountAsync(); if (criteria.Take > 0) { var ids = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id) .Select(x => x.Id) .Skip(criteria.Skip).Take(criteria.Take) .ToArrayAsync(); result.Results = (await _catalogService.GetByIdsAsync(ids, criteria.ResponseGroup)).OrderBy(x => Array.IndexOf(ids, x.Id)).ToList(); } } return(result); }
public async Task <CatalogSearchResult> SearchAsync(CatalogSearchCriteria criteria) { var retVal = new CatalogSearchResult(); var workContext = _workContextFactory(); var searchCriteria = new VirtoCommerceDomainCatalogModelSearchCriteria { StoreId = workContext.CurrentStore.Id, Keyword = criteria.Keyword, ResponseGroup = criteria.ResponseGroup.ToString(), SearchInChildren = criteria.SearchInChildren, CategoryId = criteria.CategoryId, CatalogId = criteria.CatalogId, Currency = workContext.CurrentCurrency.Code, HideDirectLinkedCategories = true, Terms = criteria.Terms.ToStrings(), PricelistIds = workContext.CurrentPricelists.Where(p => p.Currency == workContext.CurrentCurrency.Code).Select(p => p.Id).ToList(), Skip = criteria.Start, Take = criteria.PageSize, Sort = criteria.SortBy }; var searchTask = _searchApi.SearchModuleSearchAsync(searchCriteria); if (criteria.CategoryId != null) { var category = await _catalogModuleApi.CatalogModuleCategoriesGetAsync(criteria.CategoryId); if (category != null) { retVal.Category = category.ToWebModel(workContext.CurrentLanguage); } } var result = await searchTask; if (result != null) { if (result.Products != null && result.Products.Any()) { var products = result.Products.Select(x => x.ToWebModel(workContext.CurrentLanguage, workContext.CurrentCurrency)).ToArray(); retVal.Products = new StorefrontPagedList <Product>(products, criteria.PageNumber, criteria.PageSize, result.ProductsTotalCount.Value, page => workContext.RequestUrl.SetQueryParameter("page", page.ToString()).ToString()); await Task.WhenAll(_pricingService.EvaluateProductPricesAsync(retVal.Products), LoadProductsInventoriesAsync(retVal.Products)); } if (result.Categories != null && result.Categories.Any()) { retVal.Categories = result.Categories.Select(x => x.ToWebModel(workContext.CurrentLanguage)); } if (result.Aggregations != null) { retVal.Aggregations = result.Aggregations.Select(x => x.ToWebModel()).ToArray(); } } return(retVal); }
/// <summary> /// Async search products by given criteria /// </summary> /// <param name="criteria"></param> /// <returns></returns> public async Task <CatalogSearchResult> SearchProductsAsync(CatalogSearchCriteria criteria) { criteria = criteria.Clone(); //exclude categories criteria.ResponseGroup = criteria.ResponseGroup & (~CatalogSearchResponseGroup.WithCategories); //include products criteria.ResponseGroup = criteria.ResponseGroup | CatalogSearchResponseGroup.WithProducts; var workContext = _workContextFactory(); var searchCriteria = criteria.ToServiceModel(workContext); var result = await _searchApi.SearchModuleSearchAsync(searchCriteria); var products = result.Products.Select(x => x.ToWebModel(workContext.CurrentLanguage, workContext.CurrentCurrency, workContext.CurrentStore)).ToList(); if (!products.IsNullOrEmpty()) { var taskList = new List <Task>(); taskList.Add(LoadProductsInventoriesAsync(products)); taskList.Add(_pricingService.EvaluateProductPricesAsync(products)); await Task.WhenAll(taskList.ToArray()); } 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[] { } }); }
public static searchModel.SearchCriteria ToSearchApiModel(this CatalogSearchCriteria criteria, WorkContext workContext) { var result = new searchModel.SearchCriteria { StoreId = workContext.CurrentStore.Id, Keyword = criteria.Keyword, ResponseGroup = criteria.ResponseGroup.ToString(), SearchInChildren = criteria.SearchInChildren, CategoryId = criteria.CategoryId, CatalogId = criteria.CatalogId, VendorId = criteria.VendorId, Currency = criteria.Currency == null ? workContext.CurrentCurrency.Code : criteria.Currency.Code, HideDirectLinkedCategories = true, Terms = criteria.Terms.ToStrings(), PricelistIds = workContext.CurrentPricelists.Where(p => p.Currency == workContext.CurrentCurrency.Code).Select(p => p.Id).ToList(), Skip = criteria.Start, Take = criteria.PageSize, Sort = criteria.SortBy }; if (criteria.VendorIds != null) { result.VendorIds = criteria.VendorIds.ToList(); } return(result); }
public async Task <ActionResult> VendorDetails(string vendorId) { var vendor = await _customerService.GetVendorByIdAsync(vendorId); if (vendor != null) { vendor.Products = new MutablePagedList <Product>((pageNumber, pageSize, sortInfos) => { var criteria = new CatalogSearchCriteria { CatalogId = base.WorkContext.CurrentStore.Catalog, VendorId = vendorId, SearchInChildren = true, PageNumber = pageNumber, PageSize = pageSize, SortBy = SortInfo.ToString(sortInfos), ResponseGroup = CatalogSearchResponseGroup.WithProducts }; var searchResult = _catalogSearchService.SearchProducts(criteria); return(searchResult.Products); }); WorkContext.CurrentPageSeo = vendor.SeoInfo; WorkContext.CurrentVendor = vendor; return(View("vendor", WorkContext)); } throw new HttpException(404, "Vendor not found. Vendor ID: '" + vendorId + "'"); }
/// <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[] { } }); }
public async Task <ActionResult> SearchCategories(CatalogSearchCriteria searchCriteria) { var retVal = await _catalogSearchService.SearchCategoriesAsync(searchCriteria); return(Json(new { Categories = retVal, MetaData = retVal.GetMetaData() })); }
protected virtual CatalogSearchCriteria GetSearchCriteria(WorkContext workContext) { var qs = HttpUtility.ParseQueryString(workContext.RequestUrl.Query); var retVal = CatalogSearchCriteria.Parse(qs); retVal.CatalogId = workContext.CurrentStore.Catalog; retVal.Currency = workContext.CurrentCurrency; retVal.Language = workContext.CurrentLanguage; return(retVal); }
public async Task <ActionResult> SearchProducts(CatalogSearchCriteria searchCriteria) { var retVal = await _catalogSearchService.SearchProductsAsync(searchCriteria); return(Json(new { Products = retVal.Products, Aggregations = retVal.Aggregations, MetaData = retVal.Products.GetMetaData() })); }
public async Task <ActionResult> Index() { //Load categories for main page (may be removed if it not necessary) var catalogSearchCriteria = new CatalogSearchCriteria { CatalogId = _workContext.CurrentStore.Catalog, ResponseGroup = CatalogSearchResponseGroup.WithCategories }; _workContext.CurrentCatalogSearchResult = await _catalogSearchService.SearchAsync(catalogSearchCriteria); return(View("index", _workContext)); }
public async Task <ActionResult <CatalogSearchResult> > SearchCatalogs([FromBody] CatalogSearchCriteria criteria) { var authorizationResult = await _authorizationService.AuthorizeAsync(User, criteria, new CatalogAuthorizationRequirement(ModuleConstants.Security.Permissions.Read)); if (!authorizationResult.Succeeded) { return(Unauthorized()); } var result = await _catalogSearchService.SearchCatalogsAsync(criteria); return(Ok(result)); }
private async Task LoadProductAssociationsAsync(IEnumerable <Product> products) { var workContext = _workContextFactory(); var allAssociations = products.SelectMany(x => x.Associations).ToList(); var allProductAssociations = allAssociations.OfType <ProductAssociation>().ToList(); var allCategoriesAssociations = allAssociations.OfType <CategoryAssociation>().ToList(); if (allProductAssociations.Any()) { var allAssociatedProducts = await GetProductsAsync(allProductAssociations.Select(x => x.ProductId).ToArray(), ItemResponseGroup.ItemInfo | ItemResponseGroup.ItemWithPrices | ItemResponseGroup.Seo); foreach (var productAssociation in allProductAssociations) { productAssociation.Product = allAssociatedProducts.FirstOrDefault(x => x.Id == productAssociation.ProductId); } } if (allCategoriesAssociations.Any()) { var allAssociatedCategories = await GetCategoriesAsync(allCategoriesAssociations.Select(x => x.CategoryId).ToArray(), CategoryResponseGroup.Info | CategoryResponseGroup.WithSeo | CategoryResponseGroup.WithOutlines | CategoryResponseGroup.WithImages); foreach (var categoryAssociation in allCategoriesAssociations) { categoryAssociation.Category = allAssociatedCategories.FirstOrDefault(x => x.Id == categoryAssociation.CategoryId); if (categoryAssociation.Category != null && categoryAssociation.Category.Products == null) { categoryAssociation.Category.Products = new MutablePagedList <Product>((pageNumber, pageSize, sortInfos) => { var criteria = new CatalogSearchCriteria { PageNumber = pageNumber, PageSize = pageSize, CatalogId = workContext.CurrentStore.Catalog, CategoryId = categoryAssociation.CategoryId, SearchInChildren = true, ResponseGroup = CatalogSearchResponseGroup.WithProducts, }; if (!sortInfos.IsNullOrEmpty()) { criteria.SortBy = SortInfo.ToString(sortInfos); } var searchResult = SearchProducts(criteria); return(searchResult.Products); }); } } } }
/// <summary> /// search categories by given criteria /// </summary> /// <param name="criteria"></param> /// <returns></returns> public IPagedList <Category> SearchCategories(CatalogSearchCriteria criteria) { var workContext = _workContextFactory(); criteria = criteria.Clone(); //exclude products criteria.ResponseGroup = criteria.ResponseGroup & (~CatalogSearchResponseGroup.WithProducts); //include categories criteria.ResponseGroup = criteria.ResponseGroup | CatalogSearchResponseGroup.WithCategories; var searchCriteria = criteria.ToCatalogApiModel(workContext); var categories = _catalogModuleApi.CatalogModuleSearchSearch(searchCriteria).Categories.Select(x => x.ToWebModel(workContext.CurrentLanguage, workContext.CurrentStore)).ToList(); //API temporary does not support paginating request to categories (that's uses PagedList with superset) return(new PagedList <Category>(categories, criteria.PageNumber, criteria.PageSize)); }
public CatalogModel(IDomainContext domainContext) { DomainContext = domainContext; Amount = 0; StartRowIndex = 0; oldMaximumRows = MaximumRows; needToUpdateCount = true; oldSelectedItem = null; Entities = new List <CatalogItem>(); cacheCatalogItems = new Dictionary <int, List <CatalogItem> >(); BrandItems = new List <BrandItem>(); SearchCriteria = new CatalogSearchCriteria(); SubscribeEvents(); SelectBrandPopupItems(); }
/// <summary> /// Async search categories by given criteria /// </summary> /// <param name="criteria"></param> /// <returns></returns> public async Task <IPagedList <Category> > SearchCategoriesAsync(CatalogSearchCriteria criteria) { var workContext = _workContextFactory(); criteria = criteria.Clone(); //exclude products criteria.ResponseGroup = criteria.ResponseGroup & (~CatalogSearchResponseGroup.WithProducts); //include categories criteria.ResponseGroup = criteria.ResponseGroup | CatalogSearchResponseGroup.WithCategories; var searchCriteria = criteria.ToServiceModel(workContext); var result = await _catalogModuleApi.CatalogModuleSearchSearchAsync(searchCriteria); //API temporary does not support paginating request to categories (that's uses PagedList with superset instead StaticPagedList) return(new PagedList <Category>(result.Categories.Select(x => x.ToWebModel(workContext.CurrentLanguage, workContext.CurrentStore)), criteria.PageNumber, criteria.PageSize)); }
protected virtual IList <SortInfo> BuildSortExpression(CatalogSearchCriteria criteria) { var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = nameof(CatalogEntity.Name) } }; } return(sortInfos); }
public ResultSearchGridControl() { isUpdateTemplate = false; oldSearchCriteria = null; InitializeComponent(); InitBrushs(); columns = new Dictionary <DataGridColumn, string> { { NumberColumn, CatalogColumnNames.NumberColumnName }, { PhotoIconColumn, CatalogColumnNames.PhotoColumnName }, { CodeColumn, CatalogColumnNames.CodeColumnName }, { ArticleColumn, CatalogColumnNames.ArticleColumn }, { NameColumn, CatalogColumnNames.NameColumn }, { BrandColumn, CatalogColumnNames.BrandColumn }, { UnitColumn, CatalogColumnNames.UnitColumn }, { EnterpriceNormPackColumn, CatalogColumnNames.EnterpriceNormPackColumn }, { BatchOfSalesColumn, CatalogColumnNames.BatchOfSalesColumn }, { BalanceColumn, CatalogColumnNames.BalanceColumn }, { PriceColumn, CatalogColumnNames.PriceColumn }, { CountColumn, CatalogColumnNames.CountColumn } }; Unloaded += OnUnloaded; }
protected virtual IQueryable <CatalogEntity> BuildQuery(ICatalogRepository repository, CatalogSearchCriteria criteria) { var query = repository.Catalogs; if (!string.IsNullOrEmpty(criteria.Keyword)) { query = query.Where(x => x.Name.Contains(criteria.Keyword)); } if (!criteria.CatalogIds.IsNullOrEmpty()) { query = query.Where(x => criteria.CatalogIds.Contains(x.Id)); } return(query); }
public CatalogDirectoryModel(IDomainContext domainContext, CatalogSearchCriteria searchCriteria) { DomainContext = domainContext; SearchCriteria = searchCriteria; Entities = new List <DirectoryItem>(); }
public CatalogBrandViewModel(IDomainContext domainContext, CatalogSearchCriteria searchCriteria) { Model = new CatalogBrandModel(domainContext, searchCriteria); SearchCriteria = searchCriteria; SubscribeEvents(); }
private async Task HandleStorefrontRequest(IOwinContext context) { 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(), cacheNullValue : false); 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 }; //Initialize product response group workContext.CurrentProductResponseGroup = EnumUtility.SafeParse(qs.Get("resp_group"), ItemResponseGroup.ItemLarge); workContext.PageNumber = qs.Get("page").ToNullableInt(); workContext.PageSize = qs.Get("count").ToNullableInt() ?? qs.Get("page_size").ToNullableInt(); //This line make delay categories loading initialization (categories can be evaluated on view rendering time) workContext.Categories = new MutablePagedList <Category>((pageNumber, pageSize, sortInfos) => { var criteria = new CatalogSearchCriteria(workContext.CurrentLanguage, workContext.CurrentCurrency) { CatalogId = workContext.CurrentStore.Catalog, SearchInChildren = true, PageNumber = pageNumber, PageSize = pageSize, ResponseGroup = CatalogSearchResponseGroup.WithCategories | CatalogSearchResponseGroup.WithOutlines }; if (string.IsNullOrEmpty(criteria.SortBy) && !sortInfos.IsNullOrEmpty()) { criteria.SortBy = SortInfo.ToString(sortInfos); } var result = catalogSearchService.SearchCategories(criteria); foreach (var category in result) { category.Products = new MutablePagedList <Product>((pageNumber2, pageSize2, sortInfos2) => { criteria.CategoryId = category.Id; criteria.PageNumber = pageNumber2; criteria.PageSize = pageSize2; if (string.IsNullOrEmpty(criteria.SortBy) && !sortInfos2.IsNullOrEmpty()) { criteria.SortBy = SortInfo.ToString(sortInfos2); } 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, sortInfos) => { var criteria = workContext.CurrentCatalogSearchCriteria.Clone(); criteria.PageNumber = pageNumber; criteria.PageSize = pageSize; if (string.IsNullOrEmpty(criteria.SortBy) && !sortInfos.IsNullOrEmpty()) { criteria.SortBy = SortInfo.ToString(sortInfos); } 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, sortInfos) => { var criteria = workContext.CurrentCatalogSearchCriteria.Clone(); criteria.PageNumber = pageNumber; criteria.PageSize = pageSize; if (string.IsNullOrEmpty(criteria.SortBy) && !sortInfos.IsNullOrEmpty()) { criteria.SortBy = SortInfo.ToString(sortInfos); } //Force to load products and its also populate workContext.Aggregations by preloaded values workContext.Products.Slice(pageNumber, pageSize, sortInfos); 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.GroupBy(x => x.Name).Select(x => x.FindWithLanguage(workContext.CurrentLanguage)).Where(x => x != null).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.Where(x => x.Language.IsInvariant || x.Language == workContext.CurrentLanguage)); workContext.Blogs = new MutablePagedList <Blog>(staticContents.Blogs.Where(x => x.Language.IsInvariant || x.Language == workContext.CurrentLanguage)); // 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 PricingModule.Client.Model.PriceEvaluationContext { 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()); }); //Vendors with their products workContext.Vendors = new MutablePagedList <Vendor>((pageNumber, pageSize, sortInfos) => { var customerService = _container.Resolve <ICustomerService>(); var vendors = customerService.SearchVendors(null, pageNumber, pageSize, sortInfos); foreach (var vendor in vendors) { vendor.Products = new MutablePagedList <Product>((pageNumber2, pageSize2, sortInfos2) => { var criteria = new CatalogSearchCriteria { CatalogId = workContext.CurrentStore.Catalog, VendorId = vendor.Id, SearchInChildren = true, PageNumber = pageNumber2, PageSize = pageSize2, SortBy = SortInfo.ToString(sortInfos2), ResponseGroup = CatalogSearchResponseGroup.WithProducts }; var searchResult = catalogSearchService.SearchProducts(criteria); return(searchResult.Products); }); } return(vendors); }); } } }
public CatalogBrandModel(IDomainContext domainContext, CatalogSearchCriteria searchCriteria) { DomainContext = domainContext; SearchCriteria = searchCriteria; Entities = new List <BrandItem>(); }
public async Task <CatalogSearchResult> SearchAsync(CatalogSearchCriteria criteria) { var retVal = new CatalogSearchResult(); string sort = "manual"; string sortOrder = "asc"; if (!string.IsNullOrEmpty(criteria.SortBy)) { var splittedSortBy = criteria.SortBy.Split('-'); if (splittedSortBy.Length > 1) { sort = splittedSortBy[0].Equals("title", StringComparison.OrdinalIgnoreCase) ? "name" : splittedSortBy[0]; sortOrder = splittedSortBy[1].IndexOf("descending", StringComparison.OrdinalIgnoreCase) >= 0 ? "desc" : "asc"; } } var result = await _searchApi.SearchModuleSearchAsync( criteriaStoreId : _workContext.CurrentStore.Id, criteriaKeyword : criteria.Keyword, criteriaResponseGroup : criteria.ResponseGroup.ToString(), criteriaSearchInChildren : true, criteriaCategoryId : criteria.CategoryId, criteriaCatalogId : criteria.CatalogId, criteriaCurrency : _workContext.CurrentCurrency.Code, criteriaHideDirectLinkedCategories : true, criteriaTerms : criteria.Terms.ToStrings(), criteriaPricelistIds : _workContext.CurrentPriceListIds.ToList(), criteriaSkip : criteria.PageSize *(criteria.PageNumber - 1), criteriaTake : criteria.PageSize, criteriaSort : sort, criteriaSortOrder : sortOrder); if (criteria.CategoryId != null) { var category = await _catalogModuleApi.CatalogModuleCategoriesGetAsync(criteria.CategoryId); if (category != null) { retVal.Category = category.ToWebModel(); } } if (result != null) { if (result.Products != null && result.Products.Any()) { var products = result.Products.Select(x => x.ToWebModel(_workContext.CurrentLanguage, _workContext.CurrentCurrency)).ToArray(); retVal.Products = new StorefrontPagedList <Product>(products, criteria.PageNumber, criteria.PageSize, result.ProductsTotalCount.Value, page => _workContext.RequestUrl.SetQueryParameter("page", page.ToString()).ToString()); LoadProductsPrices(retVal.Products.ToArray()); LoadProductsInventories(retVal.Products.ToArray()); } if (result.Categories != null && result.Categories.Any()) { retVal.Categories = result.Categories.Select(x => x.ToWebModel()); } if (result.Aggregations != null) { retVal.Aggregations = result.Aggregations.Select(x => x.ToWebModel()).ToArray(); } } return(retVal); }
public CatalogDirectoryViewModel(IDomainContext domainContext, CatalogSearchCriteria searchCriteria) { this.searchCriteria = searchCriteria; Model = new CatalogDirectoryModel(domainContext, searchCriteria); SubscribeEvents(); }
public async Task <ActionResult> SearchProducts(CatalogSearchCriteria searchCriteria) { var retVal = await _catalogSearchService.SearchAsync(searchCriteria); return(Json(retVal)); }