Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Add new page - categories all
support332a423fab58
diff --git a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xmlindex 43acc4ffc..ee84ce91f 100644--- a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml+++ b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml@@ -12590,6 +12590,9 @@<Resource Name="Categories.Breadcrumb.Top" Area="Front"><Value>Home</Value></Resource>+ <Resource Name="Categories.List" Area="Front">+ <Value>Categories List</Value>+ </Resource><Resource Name="Categories.TotalProducts" Area="Front"><Value>({0})</Value></Resource>@@ -15806,6 +15809,9 @@<Resource Name="Title.Brands" Area="Front"><Value>Brands</Value></Resource>+ <Resource Name="Title.Categories" Area="Front">+ <Value>Categories</Value>+ </Resource><Resource Name="Title.Checkout" Area="Front"><Value>Checkout</Value></Resource>diff --git a/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_210.xml b/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_210.xmlindex 549cd28d7..491dfea6b 100644--- a/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_210.xml+++ b/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_210.xml@@ -57,4 +57,10 @@<Resource Name="Admin.Settings.Catalog.MaxCatalogPageSize" Area="Admin"><Value>Page size for the all page of brand/collection/vendor/category</Value></Resource>+ <Resource Name="Title.Categories" Area="Front">+ <Value>Categories</Value>+ </Resource>+ <Resource Name="Categories.List" Area="Front">+ <Value>Categories List</Value>+ </Resource></Language>\ No newline at end of filediff --git a/src/Web/Grand.Web/Controllers/CatalogController.cs b/src/Web/Grand.Web/Controllers/CatalogController.csindex 66500381d..704126eac 100644--- a/src/Web/Grand.Web/Controllers/CatalogController.cs+++ b/src/Web/Grand.Web/Controllers/CatalogController.cs@@ -152,6 +152,18 @@ namespace Grand.Web.Controllersreturn View(layoutViewPath, model);}+ [HttpGet]+ public virtual async Task<IActionResult> CategoryAll(CategoryPagingModel command)+ {+ var model = await _mediator.Send(new GetCategoryAll {+ Customer = _workContext.CurrentCustomer,+ Language = _workContext.WorkingLanguage,+ Store = _workContext.CurrentStore,+ Command = command+ });+ return View(model);+ }+#endregiondiff --git a/src/Web/Grand.Web/Endpoints/EndpointProvider.cs b/src/Web/Grand.Web/Endpoints/EndpointProvider.csindex 5e9137e29..ae2de9dc0 100644--- a/src/Web/Grand.Web/Endpoints/EndpointProvider.cs+++ b/src/Web/Grand.Web/Endpoints/EndpointProvider.cs@@ -229,6 +229,11 @@ namespace Grand.Web.Endpointspattern + "producttag/all/",new { controller = "Catalog", action = "ProductTagsAll" });+ //categories+ endpointRouteBuilder.MapControllerRoute("CategoryList",+ pattern + "category/all/",+ new { controller = "Catalog", action = "CategoryAll" });+//brandsendpointRouteBuilder.MapControllerRoute("BrandList",pattern + "brand/all/",diff --git a/src/Web/Grand.Web/Features/Handlers/Catalog/GetCategoryAllHandler.cs b/src/Web/Grand.Web/Features/Handlers/Catalog/GetCategoryAllHandler.csnew file mode 100644index 000000000..2b104b0dd--- /dev/null+++ b/src/Web/Grand.Web/Features/Handlers/Catalog/GetCategoryAllHandler.cs@@ -0,0 +1,100 @@+using Grand.Business.Core.Extensions;+using Grand.Business.Core.Interfaces.Catalog.Categories;+using Grand.Business.Core.Interfaces.Common.Localization;+using Grand.Business.Core.Interfaces.Storage;+using Grand.Domain.Catalog;+using Grand.Domain.Media;+using Grand.Web.Extensions;+using Grand.Web.Features.Models.Catalog;+using Grand.Web.Models.Catalog;+using Grand.Web.Models.Media;+using MediatR;++namespace Grand.Web.Features.Handlers.Catalog+{+ public class GetCategoryAllHandler : IRequestHandler<GetCategoryAll, CategoryListModel>+ {+ private readonly ICategoryService _categoryService;+ private readonly IPictureService _pictureService;+ private readonly ITranslationService _translationService;+ private readonly MediaSettings _mediaSettings;+ private readonly CatalogSettings _catalogSettings;++ public GetCategoryAllHandler(ICategoryService categoryService,+ IPictureService pictureService,+ ITranslationService translationService,+ MediaSettings mediaSettings,+ CatalogSettings catalogSettings)+ {+ _categoryService = categoryService;+ _pictureService = pictureService;+ _translationService = translationService;+ _mediaSettings = mediaSettings;+ _catalogSettings = catalogSettings;+ }++ public async Task<CategoryListModel> Handle(GetCategoryAll request, CancellationToken cancellationToken)+ {+ var model = new CategoryListModel();+ model.CategoriesModel = await PrepareCategories(request, model);+ return model;+ }++ private async Task<List<CategoryModel>> PrepareCategories(GetCategoryAll request, CategoryListModel categoryListModel)+ {+ if (request.Command.PageNumber <= 0) request.Command.PageNumber = 1;+ if (request.Command.PageSize == 0 || request.Command.PageSize > _catalogSettings.MaxCatalogPageSize)+ {+ request.Command.PageSize = _catalogSettings.MaxCatalogPageSize;+ }++ var model = new List<CategoryModel>();+ var categories = await _categoryService.GetAllCategories(storeId: request.Store.Id,+ pageIndex: request.Command.PageNumber - 1,+ pageSize: request.Command.PageSize+ );++ categoryListModel.PagingModel.LoadPagedList(categories);++ foreach (var category in categories)+ {+ model.Add(await BuildCategory(category, request));+ }++ return model;+ }++ private async Task<CategoryModel> BuildCategory(Category category, GetCategoryAll request)+ {+ var model = category.ToModel(request.Language);++ //prepare picture model+ var picture = !string.IsNullOrEmpty(category.PictureId)+ ? await _pictureService.GetPictureById(category.PictureId)+ : null;+ model.PictureModel = new PictureModel {+ Id = category.PictureId,+ FullSizeImageUrl = await _pictureService.GetPictureUrl(category.PictureId),+ ImageUrl = await _pictureService.GetPictureUrl(category.PictureId, _mediaSettings.BrandThumbPictureSize),+ Style = picture?.Style,+ ExtraField = picture?.ExtraField,+ //"title" attribute+ Title =+ picture != null &&+ !string.IsNullOrEmpty(picture.GetTranslation(x => x.TitleAttribute, request.Language.Id))+ ? picture.GetTranslation(x => x.TitleAttribute, request.Language.Id)+ : string.Format(_translationService.GetResource("Media.Brand.ImageLinkTitleFormat"),+ category.Name),+ //"alt" attribute+ AlternateText =+ picture != null &&+ !string.IsNullOrEmpty(picture.GetTranslation(x => x.AltAttribute, request.Language.Id))+ ? picture.GetTranslation(x => x.AltAttribute, request.Language.Id)+ : string.Format(_translationService.GetResource("Media.Brand.ImageAlternateTextFormat"),+ category.Name)+ };++ return model;+ }+ }+}\ No newline at end of filediff --git a/src/Web/Grand.Web/Features/Models/Catalog/GetCategoryAll.cs b/src/Web/Grand.Web/Features/Models/Catalog/GetCategoryAll.csnew file mode 100644index 000000000..3feea4d0c--- /dev/null+++ b/src/Web/Grand.Web/Features/Models/Catalog/GetCategoryAll.cs@@ -0,0 +1,16 @@+using Grand.Domain.Customers;+using Grand.Domain.Localization;+using Grand.Domain.Stores;+using Grand.Web.Models.Catalog;+using MediatR;++namespace Grand.Web.Features.Models.Catalog+{+ public class GetCategoryAll : IRequest<CategoryListModel>+ {+ public Store Store { get; set; }+ public Customer Customer { get; set; }+ public Language Language { get; set; }+ public CategoryPagingModel Command { get; set; }+ }+}diff --git a/src/Web/Grand.Web/Models/Catalog/CategoryListModel.cs b/src/Web/Grand.Web/Models/Catalog/CategoryListModel.csnew file mode 100644index 000000000..5cf133eda--- /dev/null+++ b/src/Web/Grand.Web/Models/Catalog/CategoryListModel.cs@@ -0,0 +1,12 @@+namespace Grand.Web.Models.Catalog;++public class CategoryListModel+{+ public CategoryListModel()+ {+ PagingModel = new CategoryPagingModel();+ CategoriesModel = new List<CategoryModel>();+ }+ public CategoryPagingModel PagingModel { get; set; }+ public IList<CategoryModel> CategoriesModel { get; set; }+}\ No newline at end of filediff --git a/src/Web/Grand.Web/Models/Catalog/CategoryPagingModel.cs b/src/Web/Grand.Web/Models/Catalog/CategoryPagingModel.csnew file mode 100644index 000000000..55080b12e--- /dev/null+++ b/src/Web/Grand.Web/Models/Catalog/CategoryPagingModel.cs@@ -0,0 +1,8 @@+using Grand.Web.Common.Page.Paging;++namespace Grand.Web.Models.Catalog;++public class CategoryPagingModel: BasePageableModel+{++}\ No newline at end of filediff --git a/src/Web/Grand.Web/Views/Catalog/CategoryAll.cshtml b/src/Web/Grand.Web/Views/Catalog/CategoryAll.cshtmlnew file mode 100644index 000000000..cb02e293d--- /dev/null+++ b/src/Web/Grand.Web/Views/Catalog/CategoryAll.cshtml@@ -0,0 +1,32 @@+@model CategoryListModel+@inject IPageHeadBuilder pagebuilder+@{+ Layout = "_SingleColumn";++ //title+ pagebuilder.AddTitleParts(Loc["Title.Categories"]);+}+<div class="page category-page">+ <h1 class="generalTitle h2">@Loc["Categories.List"]</h1>+ <div class="col-12 categoryGrid px-0">+ <div class="form-row">+ @foreach (var item in Model.CategoriesModel)+ {+ <div class="col-md-4 col-6 mb-2">+ <a href="@Url.RouteUrl("Category", new { item.SeName })" title="@item.PictureModel.Title">+ <div class="card mb-2">+ <img class="img-fluid" src="@item.PictureModel.ImageUrl" alt="@item.PictureModel.AlternateText">+ <div class="card-body">+ <h5>@item.Name</h5>+ </div>+ </div>+ </a>+ </div>+ }+ </div>+ @if (Model.CategoriesModel.Any())+ {+ <page-navigation asp-query-param="pagenumber" asp-pagination="Model.PagingModel"/>+ }+ </div>+</div>\ No newline at end of file