Beispiel #1
0
        /// <summary>
        /// Search categories by given criteria
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public virtual IPagedList <Category> SearchCategories(CategorySearchCriteria criteria)
        {
            var workContext = _workContextFactory();

            criteria = criteria.Clone();
            var searchCriteria = criteria.ToCategorySearchDto(workContext);
            var categories     = _searchApi.SearchApiModule.SearchCategories(workContext.CurrentStore.Id, searchCriteria).Categories.Select(x => x.ToCategory(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));
        }
Beispiel #2
0
        /// <summary>
        /// Async search categories by given criteria
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public virtual async Task <IPagedList <Category> > SearchCategoriesAsync(CategorySearchCriteria criteria)
        {
            var workContext = _workContextFactory();

            criteria = criteria.Clone();
            var searchCriteria = criteria.ToCategorySearchDto(workContext);
            var result         = await _searchApi.SearchApiModule.SearchCategoriesAsync(workContext.CurrentStore.Id, 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.ToCategory(workContext.CurrentLanguage, workContext.CurrentStore)), criteria.PageNumber, criteria.PageSize));
        }
        private async Task <IPagedList <Category> > InnerSearchCategoriesAsync(CategorySearchCriteria criteria, WorkContext workContext)
        {
            criteria = criteria.Clone();
            var searchCriteria = criteria.ToCategorySearchDto(workContext);
            var result         = await _searchApi.SearchApiModule.SearchCategoriesAsync(workContext.CurrentStore.Id, searchCriteria);

            var retVal = new PagedList <Category>(result.Categories.Select(x => x.ToCategory(workContext.CurrentLanguage, workContext.CurrentStore)), criteria.PageNumber, criteria.PageSize);

            //Set  lazy loading for child categories
            SetChildCategoriesLazyLoading(retVal.ToArray());
            return(retVal);
        }
        private async Task <IPagedList <Category> > InnerSearchCategoriesAsync(CategorySearchCriteria criteria, WorkContext workContext)
        {
            criteria = criteria.Clone();
            var searchCriteria = criteria.ToCategorySearchCriteriaDto(workContext);
            var result         = await _catalogModuleApi.CatalogModuleSearch.SearchCategoriesAsync(searchCriteria);

            var retVal = new PagedList <Category>(new List <Category>(), 1, 1);

            if (result.Items != null)
            {
                retVal = new PagedList <Category>(result.Items.Select(x => x.ToCategory(workContext.CurrentLanguage, workContext.CurrentStore)), criteria.PageNumber, criteria.PageSize);
            }

            //Set  lazy loading for child categories
            SetChildCategoriesLazyLoading(retVal.ToArray());
            return(retVal);
        }
Beispiel #5
0
        private async Task <IPagedList <Category> > InnerSearchCategoriesAsync(CategorySearchCriteria criteria, WorkContext workContext)
        {
            var cacheKey     = CacheKey.With(GetType(), "InnerSearchCategoriesAsync", criteria.GetCacheKey(), workContext.CurrentStore.Id, workContext.CurrentLanguage.CultureName, workContext.CurrentCurrency.Code);
            var searchResult = await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(CatalogCacheRegion.CreateChangeToken());
                cacheEntry.AddExpirationToken(_apiChangesWatcher.CreateChangeToken());

                criteria           = criteria.Clone();
                var searchCriteria = criteria.ToCategorySearchCriteriaDto(workContext);
                return(await _searchApi.SearchCategoriesAsync(searchCriteria));
            });

            var result = new PagedList <Category>(new List <Category>().AsQueryable(), 1, 1);

            if (searchResult.Items != null)
            {
                result = new PagedList <Category>(searchResult.Items.Select(x => x.ToCategory(workContext.CurrentLanguage, workContext.CurrentStore)).AsQueryable(), criteria.PageNumber, criteria.PageSize);
            }
            //Set  lazy loading for child categories
            SetChildCategoriesLazyLoading(result.ToArray());
            return(result);
        }
        /// <summary>
        /// Async search categories by given criteria
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public virtual async Task <IPagedList <Category> > SearchCategoriesAsync(CategorySearchCriteria criteria)
        {
            var workContext  = _workContextAccessor.WorkContext;
            var cacheKey     = CacheKey.With(GetType(), nameof(SearchCategoriesAsync), criteria.GetCacheKey(), workContext.CurrentStore.Id, workContext.CurrentLanguage.CultureName, workContext.CurrentCurrency.Code);
            var searchResult = await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(CatalogCacheRegion.CreateChangeToken());
                cacheEntry.AddExpirationToken(_apiChangesWatcher.CreateChangeToken());

                criteria           = criteria.Clone() as CategorySearchCriteria;
                var searchCriteria = criteria.ToCategorySearchCriteriaDto(workContext);
                return(await _searchApi.SearchCategoriesAsync(searchCriteria));
            });

            var result = new PagedList <Category>(new List <Category>().AsQueryable(), 1, 1);

            if (searchResult.Items != null)
            {
                result = new PagedList <Category>(searchResult.Items.Select(x => x.ToCategory(workContext.CurrentLanguage, workContext.CurrentStore)).AsQueryable(), criteria.PageNumber, criteria.PageSize);
            }
            //Set  lazy loading for child categories
            EstablishLazyDependenciesForCategories(result.ToArray());
            return(result);
        }