Skip to content

Commit c5beae4

Browse files
authored
added display order to product categories (#189)
1 parent 9800064 commit c5beae4

File tree

7 files changed

+20
-3
lines changed

7 files changed

+20
-3
lines changed

src/Modules/SimplCommerce.Module.Catalog/Components/CategoryMenuViewComponent.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public IViewComponentResult Invoke()
2121
var categories = _categoryRepository.Query().Where(x => !x.IsDeleted && x.IncludeInMenu).ToList();
2222

2323
var categoryMenuItems = new List<CategoryMenuItem>();
24-
foreach (var category in categories.Where(x => !x.ParentId.HasValue))
24+
var topCategories = categories.Where(x => !x.ParentId.HasValue).OrderByDescending(x => x.DisplayOrder);
25+
foreach (var category in topCategories)
2526
{
2627
var categoryMenuItem = Map(category);
2728
categoryMenuItems.Add(categoryMenuItem);
@@ -40,7 +41,7 @@ private CategoryMenuItem Map(Category category)
4041
};
4142

4243
var childCategories = category.Children;
43-
foreach (var childCategory in childCategories)
44+
foreach (var childCategory in childCategories.OrderByDescending(x => x.DisplayOrder))
4445
{
4546
var childCategoryMenuItem = Map(childCategory);
4647
categoryMenuItem.AddChildItem(childCategoryMenuItem);

src/Modules/SimplCommerce.Module.Catalog/Controllers/CategoryApiController.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public IActionResult Get(long id)
4848
{
4949
Id = category.Id,
5050
Name = category.Name,
51+
DisplayOrder = category.DisplayOrder,
5152
Description = category.Description,
5253
ParentId = category.ParentId,
5354
IncludeInMenu = category.IncludeInMenu,
@@ -68,6 +69,7 @@ public IActionResult Post(CategoryForm model)
6869
{
6970
Name = model.Name,
7071
SeoTitle = model.Name.ToUrlFriendly(),
72+
DisplayOrder = model.DisplayOrder,
7173
Description = model.Description,
7274
ParentId = model.ParentId,
7375
IncludeInMenu = model.IncludeInMenu,
@@ -93,6 +95,7 @@ public IActionResult Put(long id, CategoryForm model)
9395
category.Name = model.Name;
9496
category.SeoTitle = model.Name.ToUrlFriendly();
9597
category.Description = model.Description;
98+
category.DisplayOrder = model.DisplayOrder;
9699
category.ParentId = model.ParentId;
97100
category.IncludeInMenu = model.IncludeInMenu;
98101
category.IsPublished = model.IsPublished;

src/Modules/SimplCommerce.Module.Catalog/Services/CategoryService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public IList<CategoryListItem> GetAll()
3131
Id = category.Id,
3232
IsPublished = category.IsPublished,
3333
IncludeInMenu = category.IncludeInMenu,
34-
Name = category.Name
34+
Name = category.Name,
35+
DisplayOrder = category.DisplayOrder
3536
};
3637

3738
var parentCategory = category.Parent;

src/Modules/SimplCommerce.Module.Catalog/ViewModels/CategoryForm.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public CategoryForm()
1717

1818
public string Description { get; set; }
1919

20+
public int DisplayOrder { get; set; }
21+
2022
public long? ParentId { get; set; }
2123

2224
public bool IncludeInMenu { get; set; }

src/Modules/SimplCommerce.Module.Catalog/ViewModels/CategoryListItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public class CategoryListItem
66

77
public string Name { get; set; }
88

9+
public int DisplayOrder { get; set; }
10+
911
public bool IncludeInMenu { get; set; }
1012

1113
public bool IsPublished { get; set; }

src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/category/category-form.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ <h2 ng-if="vm.isEditMode">{{::vm.translate.get('Edit Category')}}</h2>
3333
<textarea name="description" ng-model="vm.category.description" rows="3" class="form-control" />
3434
</div>
3535
</div>
36+
<div class="form-group">
37+
<label class="col-sm-2 control-label">{{::vm.translate.get('Display order')}}</label>
38+
<div class="col-sm-10">
39+
<input type="number" name="displayOrder" ng-model="vm.category.displayOrder" class="form-control" />
40+
</div>
41+
</div>
3642
<div class="form-group">
3743
<label class="col-sm-2 control-label">{{::vm.translate.get('Thumbnail')}}</label>
3844
<div class="col-sm-10">

src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/category/category-list.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ <h2>{{::vm.translate.get('Categories')}}</h2>
1414
<tr>
1515
<th>{{::vm.translate.get('Name')}}</th>
1616
<th>{{::vm.translate.get('Include in menu')}}</th>
17+
<th>{{::vm.translate.get('Display order')}}</th>
1718
<th class="text-center">{{::vm.translate.get('Is Published')}}</th>
1819
<th>{{::vm.translate.get('Actions')}}</th>
1920
</tr>
@@ -22,6 +23,7 @@ <h2>{{::vm.translate.get('Categories')}}</h2>
2223
<tr ng-repeat="category in vm.categories">
2324
<td>{{category.name}}</td>
2425
<td class="text-center"><i ng-attr-class="{{category.includeInMenu && 'fa fa-circle' || 'fa fa-circle-o'}}"></i></td>
26+
<td>{{category.displayOrder}}</td>
2527
<td class="text-center"><i ng-attr-class="{{category.isPublished && 'fa fa-circle' || 'fa fa-circle-o'}}"></i></td>
2628
<td>
2729
<a ui-sref="category-edit({id: category.id})" title="Edit" class="btn btn-primary btn-xs"> <span class="glyphicon glyphicon-pencil"></span></a>

0 commit comments

Comments
 (0)