Skip to content

Commit fbdc2de

Browse files
committed
Setting to display sub-categories on a category page (hide, above products, bottom of page)
1 parent 6123f47 commit fbdc2de

9 files changed

Lines changed: 75 additions & 34 deletions

File tree

src/Libraries/SmartStore.Core/Domain/Catalog/CatalogSettings.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
namespace SmartStore.Core.Domain.Catalog
55
{
6+
public enum SubCategoryDisplayType
7+
{
8+
Hide = 0,
9+
AboveProductList = 5,
10+
Bottom = 10
11+
}
612

713
public class CatalogSettings : ISettings
814
{
@@ -26,7 +32,7 @@ public CatalogSettings()
2632
CompareProductsEnabled = true;
2733
FilterEnabled = true;
2834
MaxFilterItemsToDisplay = 4;
29-
ShowSubcategoriesAboveProductLists = true;
35+
SubCategoryDisplayType = SubCategoryDisplayType.AboveProductList;
3036
ProductSearchAutoCompleteEnabled = true;
3137
ShowProductImagesInSearchAutoComplete = true;
3238
ProductSearchAutoCompleteNumberOfProducts = 10;
@@ -162,10 +168,10 @@ public CatalogSettings()
162168
/// </summary>
163169
public bool ExpandAllFilterCriteria { get; set; }
164170

165-
/// <summary>
166-
/// Gets or sets a value indicating whether sub categories above product lists are enabled
167-
/// </summary>
168-
public bool ShowSubcategoriesAboveProductLists { get; set; }
171+
/// <summary>
172+
/// Gets or sets a value indicating whether and where to display a list of subcategories
173+
/// </summary>
174+
public SubCategoryDisplayType SubCategoryDisplayType { get; set; }
169175

170176
/// <summary>
171177
/// Gets or sets a value indicating whether a 'Share button' is enabled

src/Libraries/SmartStore.Data/Migrations/201504290937512_SendEmailsManually.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@ public void MigrateLocaleResources(LocaleResourcesBuilder builder)
7676
builder.AddOrUpdate("Admin.Orders.Payments.NewIpn.Hint",
7777
"A new notification from the payment provider has arrived in the order notes.",
7878
"In den Auftragsnotizen ist eine neue Benachrichtigung vom Zahlungsanbieter eingetroffen.");
79+
80+
81+
builder.AddOrUpdate("Admin.Configuration.Settings.Catalog.SubCategoryDisplayType",
82+
"Show subcategories",
83+
"Unterwarengruppen anzeigen",
84+
"Indicates whether and where to show subcategories on a category page.",
85+
"Legt fest, ob und wo Unterwarengruppen auf einer Warengruppenseite angezeigt werden sollen.");
86+
87+
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Catalog.SubCategoryDisplayType.Hide",
88+
"Do not display",
89+
"Nicht anzeigen");
90+
91+
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Catalog.SubCategoryDisplayType.AboveProductList",
92+
"Above product list",
93+
"Über der Produktliste");
94+
95+
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Catalog.SubCategoryDisplayType.Bottom",
96+
"At bottom of page",
97+
"Am Seitenende");
7998
}
8099
}
81100
}

src/Presentation/SmartStore.Web/Administration/Controllers/SettingController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,8 @@ public ActionResult Catalog()
566566

567567
StoreDependingSettings.GetOverrideKeys(catalogSettings, model, storeScope, _settingService);
568568

569+
model.AvailableSubCategoryDisplayTypes = catalogSettings.SubCategoryDisplayType.ToSelectList();
570+
569571
model.AvailableDefaultViewModes.Add(
570572
new SelectListItem { Value = "grid", Text = _localizationService.GetResource("Common.Grid"), Selected = model.DefaultViewMode.IsCaseInsensitiveEqual("grid") }
571573
);

src/Presentation/SmartStore.Web/Administration/Infrastructure/AutoMapperStartupTask.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ public void Execute()
593593
.ForMember(dest => dest.ActiveShippingRateComputationMethodSystemNames, mo => mo.Ignore())
594594
.ForMember(dest => dest.ReturnValidOptionsIfThereAreAny, mo => mo.Ignore());
595595
Mapper.CreateMap<CatalogSettings, CatalogSettingsModel>()
596+
.ForMember(dest => dest.AvailableSubCategoryDisplayTypes, mo => mo.Ignore())
596597
.ForMember(dest => dest.AvailableDefaultViewModes, mo => mo.Ignore())
597598
.ForMember(dest => dest.AvailableDeliveryTimes, mo => mo.Ignore());
598599
Mapper.CreateMap<CatalogSettingsModel, CatalogSettings>()

src/Presentation/SmartStore.Web/Administration/Models/Settings/CatalogSettingsModel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using System.Web.Mvc;
3+
using SmartStore.Core.Domain.Catalog;
34
using SmartStore.Web.Framework;
45

56
namespace SmartStore.Admin.Models.Settings
@@ -93,8 +94,9 @@ public CatalogSettingsModel()
9394
[SmartResourceDisplayName("Admin.Configuration.Settings.Catalog.ExpandAllFilterCriteria")]
9495
public bool ExpandAllFilterCriteria { get; set; }
9596

96-
[SmartResourceDisplayName("Admin.Configuration.Settings.Catalog.ShowSubcategoriesAboveProductLists")]
97-
public bool ShowSubcategoriesAboveProductLists { get; set; }
97+
[SmartResourceDisplayName("Admin.Configuration.Settings.Catalog.SubCategoryDisplayType")]
98+
public SubCategoryDisplayType SubCategoryDisplayType { get; set; }
99+
public SelectList AvailableSubCategoryDisplayTypes { get; set; }
98100

99101
#endregion
100102

src/Presentation/SmartStore.Web/Administration/Views/Setting/Catalog.cshtml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,12 @@
401401

402402
<tr>
403403
<td class="adminTitle">
404-
@Html.SmartLabelFor(model => model.ShowSubcategoriesAboveProductLists)
404+
@Html.SmartLabelFor(model => model.SubCategoryDisplayType)
405405
</td>
406406
<td class="adminData">
407-
@Html.SettingEditorFor(model => model.ShowSubcategoriesAboveProductLists)
408-
@Html.ValidationMessageFor(model => model.ShowSubcategoriesAboveProductLists)
407+
@Html.SettingOverrideCheckbox(model => Model.SubCategoryDisplayType)
408+
@Html.DropDownListFor(model => model.SubCategoryDisplayType, Model.AvailableSubCategoryDisplayTypes)
409+
@Html.ValidationMessageFor(model => model.SubCategoryDisplayType)
409410
</td>
410411
</tr>
411412

src/Presentation/SmartStore.Web/Controllers/CatalogController.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public ActionResult Category(int categoryId, CatalogPagingFilteringModel command
171171
var selectedPriceRange = model.PagingFilteringContext.PriceRangeFilter.GetSelectedPriceRange(_services.WebHelper, category.PriceRanges);
172172
decimal? minPriceConverted = null;
173173
decimal? maxPriceConverted = null;
174+
174175
if (selectedPriceRange != null)
175176
{
176177
if (selectedPriceRange.From.HasValue)
@@ -180,8 +181,6 @@ public ActionResult Category(int categoryId, CatalogPagingFilteringModel command
180181
maxPriceConverted = _currencyService.ConvertToPrimaryStoreCurrency(selectedPriceRange.To.Value, _services.WorkContext.WorkingCurrency);
181182
}
182183

183-
184-
185184
//category breadcrumb
186185
model.DisplayCategoryBreadcrumb = _catalogSettings.CategoryBreadcrumbEnabled;
187186
if (model.DisplayCategoryBreadcrumb)
@@ -190,11 +189,10 @@ public ActionResult Category(int categoryId, CatalogPagingFilteringModel command
190189
}
191190

192191
model.DisplayFilter = _catalogSettings.FilterEnabled;
193-
model.ShowSubcategoriesAboveProductLists = _catalogSettings.ShowSubcategoriesAboveProductLists;
192+
model.SubCategoryDisplayType = _catalogSettings.SubCategoryDisplayType;
194193

195194
var customerRolesIds = _services.WorkContext.CurrentCustomer.CustomerRoles.Where(x => x.Active).Select(x => x.Id).ToList();
196195

197-
198196
//subcategories
199197
model.SubCategories = _categoryService
200198
.GetAllCategoriesByParentCategoryId(categoryId)
@@ -230,8 +228,6 @@ public ActionResult Category(int categoryId, CatalogPagingFilteringModel command
230228
.ToList();
231229

232230

233-
234-
235231
// Featured products
236232
if (!_catalogSettings.IgnoreFeaturedProducts)
237233
{

src/Presentation/SmartStore.Web/Models/Catalog/CategoryModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using SmartStore.Core.Domain.Catalog;
23
using SmartStore.Web.Framework.Mvc;
34
using SmartStore.Web.Framework.UI;
45
using SmartStore.Web.Models.Media;
@@ -34,7 +35,7 @@ public CategoryModel()
3435
public IList<MenuItem> CategoryBreadcrumb { get; set; }
3536

3637
public bool DisplayFilter { get; set; }
37-
public bool ShowSubcategoriesAboveProductLists { get; set; }
38+
public SubCategoryDisplayType SubCategoryDisplayType { get; set; }
3839

3940
public IList<SubCategoryModel> SubCategories { get; set; }
4041

src/Presentation/SmartStore.Web/Views/Catalog/CategoryTemplate.ProductsInGridOrLines.cshtml

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
}
1616

1717
@using SmartStore.Core;
18+
@using SmartStore.Core.Domain.Catalog;
1819
@using SmartStore.Core.Domain.Common;
1920
@using SmartStore.Core.Domain.Seo;
2021
@using SmartStore.Core.Infrastructure;
@@ -33,6 +34,26 @@
3334
}
3435
}
3536

37+
@helper SubCategoryList()
38+
{
39+
<div class="category-grid sub-category-grid">
40+
@(Html.DataList<CategoryModel.SubCategoryModel>(Model.SubCategories, 3,
41+
@<article class="item-box equalized-column" data-equalized-column-name="subcat">
42+
<div class="category-item sub-category-item">
43+
<h2 class="category-title">
44+
<a href="@Url.RouteUrl("Category", new { SeName = item.SeName })" title="@item.PictureModel.Title">@item.Name</a>
45+
</h2>
46+
<div class="picture">
47+
<a href="@Url.RouteUrl("Category", new { SeName = item.SeName })" title="@item.PictureModel.Title">
48+
<img alt="@item.PictureModel.AlternateText" src="@item.PictureModel.ImageUrl" title="@item.PictureModel.Title" />
49+
</a>
50+
</div>
51+
</div>
52+
</article>
53+
))
54+
</div>
55+
}
56+
3657
<div class="page category-page">
3758
@if (Model.DisplayCategoryBreadcrumb) {
3859
<ul id="breadcrumb" class="breadcrumb">
@@ -71,25 +92,10 @@
7192
}
7293

7394
@*subcategories*@
74-
@if (Model.SubCategories.Count > 0 && Model.ShowSubcategoriesAboveProductLists)
95+
@if (Model.SubCategories.Count > 0 && Model.SubCategoryDisplayType == SubCategoryDisplayType.AboveProductList)
7596
{
7697
@Html.Widget("categorydetails_before_subcategories")
77-
78-
<div class="category-grid sub-category-grid">
79-
@(Html.DataList<CategoryModel.SubCategoryModel>(Model.SubCategories, 3,
80-
@<article class="item-box equalized-column" data-equalized-column-name="subcat">
81-
<div class="category-item sub-category-item">
82-
<h2 class="category-title">
83-
<a href="@Url.RouteUrl("Category", new { SeName = item.SeName })" title="@item.PictureModel.Title">@item.Name</a>
84-
</h2>
85-
<div class="picture">
86-
<a href="@Url.RouteUrl("Category", new { SeName = item.SeName })" title="@item.PictureModel.Title">
87-
<img alt="@item.PictureModel.AlternateText" src="@item.PictureModel.ImageUrl" title="@item.PictureModel.Title" /></a>
88-
</div>
89-
</div>
90-
</article>
91-
))
92-
</div>
98+
@SubCategoryList()
9399
}
94100

95101
@*featured products*@
@@ -159,6 +165,13 @@
159165
</div>
160166
}
161167

168+
@*subcategories*@
169+
@if (Model.SubCategories.Count > 0 && Model.SubCategoryDisplayType == SubCategoryDisplayType.Bottom)
170+
{
171+
@Html.Widget("categorydetails_before_subcategories")
172+
@SubCategoryList()
173+
}
174+
162175
@Html.Widget("categorydetails_bottom")
163176
</div>
164177
</div>

0 commit comments

Comments
 (0)