public async Task <MenuLinkList[]> LoadAllStoreLinkListsAsync(string storeId) { var retVal = new List <MenuLinkList>(); var linkLists = await _cmsApi.Menu.GetListsAsync(storeId); if (linkLists != null) { retVal.AddRange(linkLists.Select(x => x.ToMenuLinkList())); var allMenuLinks = retVal.SelectMany(x => x.MenuLinks).ToList(); var productLinks = allMenuLinks.OfType <ProductMenuLink>().ToList(); var categoryLinks = allMenuLinks.OfType <CategoryMenuLink>().ToList(); Task <Product[]> productsLoadingTask = null; Task <Category[]> categoriesLoadingTask = null; //Parallel loading associated objects var productIds = productLinks.Select(x => x.AssociatedObjectId).ToArray(); if (productIds.Any()) { productsLoadingTask = _catalogSearchService.GetProductsAsync(productIds, ItemResponseGroup.ItemSmall | ItemResponseGroup.Seo | ItemResponseGroup.Outlines); } var categoriesIds = categoryLinks.Select(x => x.AssociatedObjectId).ToArray(); if (categoriesIds.Any()) { categoriesLoadingTask = _catalogSearchService.GetCategoriesAsync(categoriesIds, CategoryResponseGroup.Info | CategoryResponseGroup.WithImages | CategoryResponseGroup.WithSeo | CategoryResponseGroup.WithOutlines); } //Populate link by associated product if (productsLoadingTask != null) { var products = await productsLoadingTask; foreach (var productLink in productLinks) { productLink.Product = products.FirstOrDefault(x => x.Id == productLink.AssociatedObjectId); } } //Populate link by associated category if (categoriesLoadingTask != null) { var categories = await categoriesLoadingTask; foreach (var categoryLink in categoryLinks) { categoryLink.Category = categories.FirstOrDefault(x => x.Id == categoryLink.AssociatedObjectId); } } } return(retVal.ToArray()); }
/// <summary> /// GET search/{categoryId}?view=... /// This method called from SeoRoute when url contains slug for category /// </summary> /// <param name="categoryId"></param> /// <returns></returns> public async Task <ActionResult> CategoryBrowsing(string categoryId, string view) { if (string.IsNullOrEmpty(view)) { view = "grid"; } WorkContext.CurrentCatalogSearchCriteria.CategoryId = categoryId; WorkContext.CurrentCategory = (await _searchService.GetCategoriesAsync(new[] { categoryId }, CategoryResponseGroup.Full)).FirstOrDefault(); WorkContext.CurrentCategory.Products = WorkContext.Products; if (view.Equals("list", StringComparison.OrdinalIgnoreCase)) { return(View("collection.list", WorkContext)); } return(View("collection", WorkContext)); }
public async Task <ActionResult> ProductDetails(string productId) { var product = (await _catalogSearchService.GetProductsAsync(new[] { productId }, WorkContext.CurrentProductResponseGroup)).FirstOrDefault(); WorkContext.CurrentProduct = product; if (product != null) { WorkContext.CurrentPageSeo = product.SeoInfo.JsonClone(); WorkContext.CurrentPageSeo.Slug = product.Url; // make sure title is set if (string.IsNullOrEmpty(WorkContext.CurrentPageSeo.Title)) { WorkContext.CurrentPageSeo.Title = product.Name; } if (product.CategoryId != null) { var category = (await _catalogSearchService.GetCategoriesAsync(new[] { product.CategoryId }, CategoryResponseGroup.Full)).FirstOrDefault(); WorkContext.CurrentCategory = category; if (category != null) { category.Products = new MutablePagedList <Product>((pageNumber, pageSize, sortInfos) => { var criteria = WorkContext.CurrentProductSearchCriteria.Clone(); criteria.Outline = product.GetCategoryOutline(); criteria.PageNumber = pageNumber; criteria.PageSize = pageSize; if (string.IsNullOrEmpty(criteria.SortBy) && !sortInfos.IsNullOrEmpty()) { criteria.SortBy = SortInfo.ToString(sortInfos); } return(_catalogSearchService.SearchProducts(criteria).Products); }); } } } return(View("product", WorkContext)); }
/// <summary> /// GET search/{categoryId}?view=... /// This method called from SeoRoute when url contains slug for category /// </summary> /// <param name="categoryId"></param> /// <param name="view"></param> /// <returns></returns> public async Task <ActionResult> CategoryBrowsing(string categoryId, string view) { var category = (await _searchService.GetCategoriesAsync(new[] { categoryId }, CategoryResponseGroup.Full)).FirstOrDefault(); if (category == null) { throw new HttpException(404, String.Format("Category {0} not found.", categoryId)); } WorkContext.CurrentCategory = category; WorkContext.CurrentProductSearchCriteria.Outline = string.Format("{0}*", category.Outline); // should we simply take it from current category? if (category != null) { category.Products = WorkContext.Products; WorkContext.CurrentPageSeo = category.SeoInfo.JsonClone(); WorkContext.CurrentPageSeo.Slug = category.Url; // make sure title is set if (string.IsNullOrEmpty(WorkContext.CurrentPageSeo.Title)) { WorkContext.CurrentPageSeo.Title = category.Name; } } if (string.IsNullOrEmpty(view)) { view = "grid"; } if (view.Equals("list", StringComparison.OrdinalIgnoreCase)) { return(View("collection.list", WorkContext)); } return(View("collection", WorkContext)); }
public async Task <ActionResult> GetCategoriesByIds(string[] categoryIds, CategoryResponseGroup respGroup = CategoryResponseGroup.Full) { var retVal = await _catalogSearchService.GetCategoriesAsync(categoryIds, respGroup); return(Json(retVal)); }