Skip to content

Commit 5ae43eb

Browse files
Closes smartstore#202 Implement option for product list 'default sort order'
1 parent ee19c3c commit 5ae43eb

8 files changed

Lines changed: 57 additions & 4 deletions

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public CatalogSettings()
1616
{
1717
FileUploadAllowedExtensions = new List<string>();
1818
AllowProductSorting = true;
19+
DefaultSortOrder = ProductSortingEnum.Position;
1920
AllowProductViewModeChanging = true;
2021
DefaultViewMode = "grid";
2122
CategoryBreadcrumbEnabled = true;
@@ -125,13 +126,18 @@ public CatalogSettings()
125126
/// </summary>
126127
public bool AllowProductSorting { get; set; }
127128

129+
/// <summary>
130+
/// Gets or sets the default sort order in product lists
131+
/// </summary>
132+
public ProductSortingEnum DefaultSortOrder { get; set; }
133+
128134
/// <summary>
129135
/// Gets or sets a value indicating whether customers are allowed to change product view mode
130136
/// </summary>
131137
public bool AllowProductViewModeChanging { get; set; }
132138

133139
/// <summary>
134-
/// Gets or sets a value indicating whether customers are allowed to change product view mode
140+
/// Gets or sets the default view mode for product lists
135141
/// </summary>
136142
public string DefaultViewMode { get; set; }
137143

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
/// </summary>
66
public enum ProductSortingEnum
77
{
8+
/// <summary>
9+
/// Initial state
10+
/// </summary>
11+
Initial = 0,
812
/// <summary>
913
/// Position (display order)
1014
/// </summary>
11-
Position = 0,
15+
Position = 1,
1216
/// <summary>
1317
/// Name: A to Z
1418
/// </summary>
@@ -32,6 +36,6 @@ public enum ProductSortingEnum
3236
/// <summary>
3337
/// Product creation date
3438
/// </summary>
35-
CreatedOnAsc = 16 // codehint: sm-add
39+
CreatedOnAsc = 16
3640
}
3741
}

src/Libraries/SmartStore.Data/Migrations/201508121735397_AddSyncMapping.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ public void MigrateLocaleResources(LocaleResourcesBuilder builder)
9999
"Enter additional paths that should be included as Disallow entries in your robots.txt. Each entry has to entered in a new line.",
100100
"Geben Sie hier zusätzliche Pfade an, die als Disallow-Einträge zur robots.txt hinzugefügt werden sollen. Jeder Eintrag muss in einer neuen Zeile erfolgen.");
101101

102+
builder.AddOrUpdate("Admin.Configuration.Settings.Catalog.DefaultSortOrderMode",
103+
"Default product sort order",
104+
"Standardsortierreihenfolge für Produkte",
105+
"Specifies the default product sort order.",
106+
"Legt die Standardsortierreihenfolge für Produkte fest.");
107+
102108
}
103109
}
104110
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,9 @@ public ActionResult Catalog()
567567
new SelectListItem { Value = "list", Text = _services.Localization.GetResource("Common.List"), Selected = model.DefaultViewMode.IsCaseInsensitiveEqual("list") }
568568
);
569569

570+
//default sort order modes
571+
model.AvailableSortOrderModes = catalogSettings.DefaultSortOrder.ToSelectList();
572+
570573
var deliveryTimes = _deliveryTimesService.GetAllDeliveryTimes();
571574
foreach (var dt in deliveryTimes)
572575
{

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ public CatalogSettingsModel()
118118
public string DefaultViewMode { get; set; }
119119
public IList<SelectListItem> AvailableDefaultViewModes { get; private set; }
120120

121+
[SmartResourceDisplayName("Admin.Configuration.Settings.Catalog.DefaultSortOrderMode")]
122+
public ProductSortingEnum DefaultSortOrder { get; set; }
123+
public SelectList AvailableSortOrderModes { get; set; }
124+
121125
[SmartResourceDisplayName("Admin.Configuration.Settings.Catalog.AllowProductViewModeChanging")]
122126
public bool AllowProductViewModeChanging { get; set; }
123127

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,16 @@
478478
@Html.ValidationMessageFor(model => model.DefaultViewMode)
479479
</td>
480480
</tr>
481+
<tr>
482+
<td class="adminTitle">
483+
@Html.SmartLabelFor(model => model.DefaultSortOrder)
484+
</td>
485+
<td class="adminData">
486+
@Html.SettingOverrideCheckbox(model => Model.DefaultSortOrder)
487+
@Html.DropDownListFor(model => model.DefaultSortOrder, Model.AvailableSortOrderModes)
488+
@Html.ValidationMessageFor(model => model.DefaultSortOrder)
489+
</td>
490+
</tr>
481491
<tr>
482492
<td class="adminTitle">
483493
@Html.SmartLabelFor(model => model.AllowProductViewModeChanging)

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ public ActionResult Category(int categoryId, CatalogPagingFilteringModel command
146146
command.ViewMode = category.DefaultViewMode;
147147
}
148148

149+
if (command.OrderBy == (int)ProductSortingEnum.Initial)
150+
{
151+
command.OrderBy = (int)_catalogSettings.DefaultSortOrder;
152+
}
153+
149154
var model = category.ToModel();
150155

151156
_helper.PreparePagingFilteringModel(model.PagingFilteringContext, command, new PageSizeContext
@@ -448,6 +453,11 @@ public ActionResult Manufacturer(int manufacturerId, CatalogPagingFilteringModel
448453
// prepare picture model
449454
model.PictureModel = _helper.PrepareManufacturerPictureModel(manufacturer, model.Name);
450455

456+
if (command.OrderBy == (int)ProductSortingEnum.Initial)
457+
{
458+
command.OrderBy = (int)_catalogSettings.DefaultSortOrder;
459+
}
460+
451461
_helper.PreparePagingFilteringModel(model.PagingFilteringContext, command, new PageSizeContext
452462
{
453463
AllowCustomersToSelectPageSize = manufacturer.AllowCustomersToSelectPageSize,
@@ -713,6 +723,11 @@ public ActionResult ProductsByTag(int productTagId, CatalogPagingFilteringModel
713723
TagName = productTag.GetLocalized(y => y.Name)
714724
};
715725

726+
if (command.OrderBy == (int)ProductSortingEnum.Initial)
727+
{
728+
command.OrderBy = (int)_catalogSettings.DefaultSortOrder;
729+
}
730+
716731
_helper.PreparePagingFilteringModel(model.PagingFilteringContext, command, new PageSizeContext
717732
{
718733
AllowCustomersToSelectPageSize = _catalogSettings.ProductsByTagAllowCustomersToSelectPageSize,
@@ -1018,6 +1033,11 @@ public ActionResult Search(SearchModel model, SearchPagingFilteringModel command
10181033
if (command.PageNumber <= 0)
10191034
command.PageNumber = 1;
10201035

1036+
if (command.OrderBy == (int)ProductSortingEnum.Initial)
1037+
{
1038+
command.OrderBy = (int)_catalogSettings.DefaultSortOrder;
1039+
}
1040+
10211041
_helper.PreparePagingFilteringModel(model.PagingFilteringContext, command, new PageSizeContext
10221042
{
10231043
AllowCustomersToSelectPageSize = _catalogSettings.ProductSearchAllowCustomersToSelectPageSize,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,7 @@ public void PreparePagingFilteringModel(PagingFilteringModel model, PagingFilter
15181518

15191519
foreach (ProductSortingEnum enumValue in Enum.GetValues(typeof(ProductSortingEnum)))
15201520
{
1521-
if (enumValue == ProductSortingEnum.CreatedOnAsc)
1521+
if (enumValue == ProductSortingEnum.CreatedOnAsc || enumValue == ProductSortingEnum.Initial)
15221522
{
15231523
// TODO: (MC) das von uns eingeführte "CreatedOnAsc" schmeiß ich
15241524
// jetzt deshalb aus der UI raus, weil wir diese Sortier-Option

0 commit comments

Comments
 (0)