matjohnson wrote:
1) Firstly, only show sub items from a specific category
call _categoryService.GetAllCategoriesByParentCategoryId( categoryId )
matjohnson wrote:
2) Show the images of that sub category on the screen.
Take a look at how its done in CatalogController.Category
Basically you create a viewmodel with the properties you want (like id, name, picturemodel etc)
Get all the subcategories (see 1) and in a loop fill a list of viewmodels
model.SubCategories = _categoryService
.GetAllCategoriesByParentCategoryId(categoryId)
.Select(x =>
{
var subCatName = x.GetLocalized(y => y.Name);
var subCatModel = new CategoryModel.SubCategoryModel()
{
Id = x.Id,
Name = subCatName,
SeName = x.GetSeName(),
};
//prepare picture model
int pictureSize = _mediaSettings.CategoryThumbPictureSize;
var categoryPictureCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_PICTURE_MODEL_KEY, x.Id, pictureSize, true, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured());
subCatModel.PictureModel = _cacheManager.Get(categoryPictureCacheKey, () =>
{
var pictureModel = new PictureModel()
{
FullSizeImageUrl = _pictureService.GetPictureUrl(x.PictureId),
ImageUrl = _pictureService.GetPictureUrl(x.PictureId, pictureSize),
Title = string.Format(_localizationService.GetResource("Media.Category.ImageLinkTitleFormat"), subCatName),
AlternateText = string.Format(_localizationService.GetResource("Media.Category.ImageAlternateTextFormat"), subCatName)
};
return pictureModel;
});
return subCatModel;
})
.ToList();
in you razor view just loop the list and create the appropriate Html