public Category GetById(string categoryId, CategoryResponseGroup responseGroup, string catalogId = null) { var cacheKey = GetCacheKey("CategoryService.GetById", categoryId, responseGroup.ToString(), catalogId); var retVal = _cacheManager.Get(cacheKey, RegionName, () => _categoryService.GetById(categoryId, responseGroup, catalogId)); return(retVal); }
public virtual Category[] GetByIds(string[] categoryIds, CategoryResponseGroup responseGroup, string catalogId = null) { var result = new List <Category>(); var preloadedCategoriesMap = PreloadCategories(catalogId); foreach (var categoryId in categoryIds.Where(x => x != null)) { Category category; if (preloadedCategoriesMap.TryGetValue(categoryId, out category)) { result.Add(MemberwiseCloneCategory(category)); } } //Reduce details according to response group foreach (var category in result) { category.ReduceDetails(responseGroup.ToString()); } return(result.ToArray()); }
public virtual async Task <Category[]> GetCategoriesAsync(string[] ids, CategoryResponseGroup responseGroup = CategoryResponseGroup.Info) { var workContext = _workContextAccessor.WorkContext; var cacheKey = CacheKey.With(GetType(), "GetCategoriesAsync", string.Join("-", ids.OrderBy(x => x)), responseGroup.ToString()); var categoriesDto = await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(CatalogCacheRegion.CreateChangeToken()); return(await _categoriesApi.GetCategoriesByPlentyIdsAsync(ids.ToList(), ((int)responseGroup).ToString())); }); var result = categoriesDto.Select(x => x.ToCategory(workContext.CurrentLanguage, workContext.CurrentStore)).ToArray(); //Set lazy loading for child categories EstablishLazyDependenciesForCategories(result); return(result); }
private async Task <Category[]> InnerGetCategoriesAsync(string[] ids, WorkContext workContext, CategoryResponseGroup responseGroup = CategoryResponseGroup.Info) { var cacheKey = CacheKey.With(GetType(), "InnerGetCategoriesAsync", string.Join("-", ids.OrderBy(x => x)), responseGroup.ToString()); var categoriesDto = await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(CatalogCacheRegion.CreateChangeToken()); return(await _categoriesApi.GetCategoriesByPlentyIdsAsync(ids.ToList(), ((int)responseGroup).ToString())); }); var result = categoriesDto.Select(x => x.ToCategory(workContext.CurrentLanguage, workContext.CurrentStore)).ToArray(); //Set lazy loading for child categories SetChildCategoriesLazyLoading(result); return(result); }
public Category[] GetByIds(string[] categoryIds, CategoryResponseGroup responseGroup, string catalogId = null) { var cacheKey = GetCacheKey("CategoryService.GetByIds", string.Join(", ", categoryIds), responseGroup.ToString(), catalogId); var retVal = _cacheManager.Get(cacheKey, RegionName, () => _categoryService.GetByIds(categoryIds, responseGroup, catalogId)); return(retVal); }
public Category[] GetByIds(string[] categoryIds, CategoryResponseGroup responseGroup, string catalogId = null) { var extCatalogs = GetExternalCatalogs(); var retVal = _categoryService.GetByIds(categoryIds, responseGroup, catalogId).ToList(); foreach (var extCatalog in extCatalogs) { var apiUrl = extCatalog.PropertyValues.FirstOrDefault(x => x.PropertyName.EqualsInvariant("apiUrl")).Value.ToString(); var extCategories = _vcCatalogClientFactory(apiUrl).CatalogModuleCategories.GetCategoriesByIds(categoryIds.ToList(), responseGroup.ToString()); foreach (var extCategory in extCategories) { var category = ConvertToCategory(extCategory); var localCategory = retVal.FirstOrDefault(x => x.Id.EqualsInvariant(extCategory.Id)); if (localCategory != null) { retVal.Remove(localCategory); category.Properties = localCategory.Properties; category.PropertyValues = localCategory.PropertyValues; category.Links = localCategory.Links; if (category.Outlines.IsNullOrEmpty()) { category.Outlines = localCategory.Outlines; } else if (!localCategory.Outlines.IsNullOrEmpty()) { category.Outlines.AddRange(localCategory.Outlines); } } retVal.Add(category); } } foreach (var category in retVal) { if (!category.PropertyValues.Any(x => x.PropertyName.EqualsInvariant("usergroups"))) { category.PropertyValues.Add(new PropertyValue { PropertyName = "usergroups", Value = "__NULL__", ValueType = PropertyValueType.ShortText }); } } return(retVal.ToArray()); }