Skip to content

Commit 8ea4660

Browse files
committed
Resolves smartstore#495 Implement option to search product detail description by default
1 parent 6101d08 commit 8ea4660

7 files changed

Lines changed: 73 additions & 61 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
* Web-API: Bridge to import framework: uploading import files to import profile directory
6262
* Setting to round down calculated reward points
6363
* #695 Implement checkbox in checkout to let customers subscribe to newsletters
64+
* #495 Implement option to search product detail description by default
6465

6566
### Improvements
6667
* (Perf) Implemented static caches for URL aliases and localized properties. Increases app startup and request speed by up to 30%.

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,15 @@ public CatalogSettings()
382382

383383
public bool SuppressSkuSearch { get; set; }
384384

385-
/// <summary>
386-
/// Gets or sets the available customer selectable default page size options
387-
/// </summary>
388-
public string DefaultPageSizeOptions { get; set; }
385+
/// <summary>
386+
/// Gets or sets a value indicating whether to search long description
387+
/// </summary>
388+
public bool SearchDescriptions { get; set; }
389+
390+
/// <summary>
391+
/// Gets or sets the available customer selectable default page size options
392+
/// </summary>
393+
public string DefaultPageSizeOptions { get; set; }
389394

390395
/// <summary>
391396
/// Gets or sets the price display type for prices in product lists

src/Libraries/SmartStore.Data/Migrations/201601262000441_ImportFramework1.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,12 @@ public void MigrateLocaleResources(LocaleResourcesBuilder builder)
461461
"Transaktions-ID für Autorisierung",
462462
"Authorization transaction identifier received from your payment gateway.",
463463
"Vom Zahlungsanbieter erhaltene Transaktions-ID für die Autorisierung.");
464+
465+
builder.AddOrUpdate("Admin.Configuration.Settings.Catalog.SearchDescriptions",
466+
"Search product description",
467+
"Produktbeschreibung durchsuchen",
468+
"Specifies whether the product description should be included in the search.",
469+
"Legt fest, ob die Produktbeschreibung in der Suche einbezogen werden soll.");
464470
}
465471
}
466472
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,10 @@ public CatalogSettingsModel()
281281
[SmartResourceDisplayName("Admin.Configuration.Settings.Catalog.SuppressSkuSearch")]
282282
public bool SuppressSkuSearch { get; set; }
283283

284-
#endregion
284+
[SmartResourceDisplayName("Admin.Configuration.Settings.Catalog.SearchDescriptions")]
285+
public bool SearchDescriptions { get; set; }
286+
287+
#endregion
285288

286-
}
289+
}
287290
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,15 @@
911911
@Html.ValidationMessageFor(model => model.SuppressSkuSearch)
912912
</td>
913913
</tr>
914+
<tr>
915+
<td class="adminTitle">
916+
@Html.SmartLabelFor(model => model.SearchDescriptions)
917+
</td>
918+
<td class="adminData">
919+
@Html.SettingEditorFor(model => model.SearchDescriptions)
920+
@Html.ValidationMessageFor(model => model.SearchDescriptions)
921+
</td>
922+
</tr>
914923
<tr>
915924
<td class="adminSeparator" colspan="2">
916925
<hr />

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

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics;
43
using System.Linq;
54
using System.ServiceModel.Syndication;
65
using System.Web.Mvc;
@@ -9,7 +8,6 @@
98
using SmartStore.Core.Domain.Catalog;
109
using SmartStore.Core.Domain.Customers;
1110
using SmartStore.Core.Domain.Media;
12-
using SmartStore.Core.Localization;
1311
using SmartStore.Services;
1412
using SmartStore.Services.Catalog;
1513
using SmartStore.Services.Common;
@@ -33,7 +31,7 @@
3331

3432
namespace SmartStore.Web.Controllers
3533
{
36-
public partial class CatalogController : PublicControllerBase
34+
public partial class CatalogController : PublicControllerBase
3735
{
3836
#region Fields
3937

@@ -1087,14 +1085,13 @@ public ActionResult Search(SearchModel model, SearchPagingFilteringModel command
10871085
_services.StoreContext.CurrentStore.Id);
10881086

10891087
if (command.PageSize <= 0)
1088+
10901089
command.PageSize = _catalogSettings.SearchPageProductsPerPage;
10911090
if (command.PageNumber <= 0)
10921091
command.PageNumber = 1;
10931092

10941093
if (command.OrderBy == (int)ProductSortingEnum.Initial)
1095-
{
10961094
command.OrderBy = (int)_catalogSettings.DefaultSortOrder;
1097-
}
10981095

10991096
_helper.PreparePagingFilteringModel(model.PagingFilteringContext, command, new PageSizeContext
11001097
{
@@ -1103,17 +1100,10 @@ public ActionResult Search(SearchModel model, SearchPagingFilteringModel command
11031100
PageSizeOptions = _catalogSettings.ProductSearchPageSizeOptions
11041101
});
11051102

1106-
if (model.Q == null)
1107-
model.Q = "";
1108-
model.Q = model.Q.Trim();
1103+
model.Q = model.Q.EmptyNull().Trim();
11091104

11101105
// Build AvailableCategories
1111-
// first empty entry
1112-
model.AvailableCategories.Add(new SelectListItem
1113-
{
1114-
Value = "0",
1115-
Text = T("Common.All")
1116-
});
1106+
model.AvailableCategories.Add(new SelectListItem { Value = "0", Text = T("Common.All") });
11171107

11181108
var navModel = _helper.PrepareCategoryNavigationModel(0, 0);
11191109

@@ -1122,7 +1112,7 @@ public ActionResult Search(SearchModel model, SearchPagingFilteringModel command
11221112
if (node.IsRoot)
11231113
return;
11241114

1125-
int id = node.Value.EntityId;
1115+
var id = node.Value.EntityId;
11261116
var breadcrumb = node.GetBreadcrumb().Select(x => x.Text).ToArray();
11271117

11281118
model.AvailableCategories.Add(new SelectListItem
@@ -1136,21 +1126,21 @@ public ActionResult Search(SearchModel model, SearchPagingFilteringModel command
11361126
var manufacturers = _manufacturerService.GetAllManufacturers();
11371127
if (manufacturers.Count > 0)
11381128
{
1139-
model.AvailableManufacturers.Add(new SelectListItem
1140-
{
1141-
Value = "0",
1142-
Text = T("Common.All")
1143-
});
1129+
model.AvailableManufacturers.Add(new SelectListItem { Value = "0", Text = T("Common.All") });
1130+
11441131
foreach (var m in manufacturers)
1132+
{
11451133
model.AvailableManufacturers.Add(new SelectListItem
11461134
{
11471135
Value = m.Id.ToString(),
11481136
Text = m.GetLocalized(x => x.Name),
11491137
Selected = model.Mid == m.Id
11501138
});
1139+
}
11511140
}
11521141

11531142
IPagedList<Product> products = new PagedList<Product>(new List<Product>(), 0, 1);
1143+
11541144
// only search if query string search keyword is set (used to avoid searching or displaying search term min length error message on /search page load)
11551145
if (Request.Params["Q"] != null)
11561146
{
@@ -1161,10 +1151,11 @@ public ActionResult Search(SearchModel model, SearchPagingFilteringModel command
11611151
else
11621152
{
11631153
var categoryIds = new List<int>();
1164-
int manufacturerId = 0;
1154+
var manufacturerId = 0;
11651155
decimal? minPriceConverted = null;
11661156
decimal? maxPriceConverted = null;
1167-
bool searchInDescriptions = false;
1157+
var searchInDescriptions = _catalogSettings.SearchDescriptions;
1158+
11681159
if (model.As)
11691160
{
11701161
// advanced search
@@ -1182,16 +1173,16 @@ public ActionResult Search(SearchModel model, SearchPagingFilteringModel command
11821173
manufacturerId = model.Mid;
11831174

11841175
// min price
1185-
if (!string.IsNullOrEmpty(model.Pf))
1176+
if (model.Pf.HasValue())
11861177
{
1187-
decimal minPrice = decimal.Zero;
1178+
var minPrice = decimal.Zero;
11881179
if (decimal.TryParse(model.Pf, out minPrice))
11891180
minPriceConverted = _currencyService.ConvertToPrimaryStoreCurrency(minPrice, _services.WorkContext.WorkingCurrency);
11901181
}
11911182
// max price
1192-
if (!string.IsNullOrEmpty(model.Pt))
1183+
if (model.Pt.HasValue())
11931184
{
1194-
decimal maxPrice = decimal.Zero;
1185+
var maxPrice = decimal.Zero;
11951186
if (decimal.TryParse(model.Pt, out maxPrice))
11961187
maxPriceConverted = _currencyService.ConvertToPrimaryStoreCurrency(maxPrice, _services.WorkContext.WorkingCurrency);
11971188
}
@@ -1202,8 +1193,6 @@ public ActionResult Search(SearchModel model, SearchPagingFilteringModel command
12021193
//var searchInProductTags = false;
12031194
var searchInProductTags = searchInDescriptions;
12041195

1205-
//products
1206-
12071196
var ctx = new ProductSearchContext();
12081197
ctx.CategoryIds = categoryIds;
12091198
ctx.ManufacturerId = manufacturerId;
@@ -1223,13 +1212,17 @@ public ActionResult Search(SearchModel model, SearchPagingFilteringModel command
12231212
products = _productService.SearchProducts(ctx);
12241213

12251214
model.Products = _helper.PrepareProductOverviewModels(
1226-
products,
1227-
prepareColorAttributes: true,
1215+
products,
1216+
prepareColorAttributes: true,
12281217
prepareManufacturers: command.ViewMode.IsCaseInsensitiveEqual("list")).ToList();
12291218

12301219
model.NoResults = !model.Products.Any();
12311220
}
12321221
}
1222+
else
1223+
{
1224+
model.Sid = _catalogSettings.SearchDescriptions;
1225+
}
12331226

12341227
model.PagingFilteringContext.LoadPagedList(products);
12351228
return View(model);
@@ -1252,35 +1245,32 @@ public ActionResult SearchTermAutoComplete(string term)
12521245
if (String.IsNullOrWhiteSpace(term) || term.Length < _catalogSettings.ProductSearchTermMinimumLength)
12531246
return Content("");
12541247

1255-
// products
1256-
var pageSize = _catalogSettings.ProductSearchAutoCompleteNumberOfProducts > 0 ? _catalogSettings.ProductSearchAutoCompleteNumberOfProducts : 10;
1257-
12581248
var ctx = new ProductSearchContext();
12591249
ctx.LanguageId = _services.WorkContext.WorkingLanguage.Id;
12601250
ctx.Keywords = term;
12611251
ctx.SearchSku = !_catalogSettings.SuppressSkuSearch;
1252+
ctx.SearchDescriptions = _catalogSettings.SearchDescriptions;
12621253
ctx.OrderBy = ProductSortingEnum.Position;
1263-
ctx.PageSize = pageSize;
1254+
ctx.PageSize = (_catalogSettings.ProductSearchAutoCompleteNumberOfProducts > 0 ? _catalogSettings.ProductSearchAutoCompleteNumberOfProducts : 10);
12641255
ctx.StoreId = _services.StoreContext.CurrentStoreIdIfMultiStoreMode;
12651256
ctx.VisibleIndividuallyOnly = true;
12661257

12671258
var products = _productService.SearchProducts(ctx);
12681259

1269-
var models = _helper.PrepareProductOverviewModels(
1270-
products,
1260+
var models = _helper.PrepareProductOverviewModels(products,
12711261
false,
12721262
_catalogSettings.ShowProductImagesInSearchAutoComplete,
1273-
_mediaSettings.ProductThumbPictureSizeOnProductDetailsPage).ToList();
1274-
1275-
var result = (from p in models
1276-
select new
1277-
{
1278-
label = p.Name,
1279-
secondary = p.ShortDescription.Truncate(70, "...") ?? "",
1280-
producturl = Url.RouteUrl("Product", new { SeName = p.SeName }),
1281-
productpictureurl = p.DefaultPictureModel.ImageUrl
1282-
})
1283-
.ToList();
1263+
_mediaSettings.ProductThumbPictureSizeOnProductDetailsPage
1264+
).ToList();
1265+
1266+
var result = models.Select(x => new
1267+
{
1268+
label = x.Name,
1269+
secondary = x.ShortDescription.Truncate(70, "...") ?? "",
1270+
producturl = Url.RouteUrl("Product", new { SeName = x.SeName }),
1271+
productpictureurl = x.DefaultPictureModel.ImageUrl
1272+
}).ToList();
1273+
12841274
return Json(result, JsonRequestBehavior.AllowGet);
12851275
}
12861276

src/Presentation/SmartStore.Web/Views/Catalog/Search.cshtml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
@model SearchModel
1+
@using SmartStore.Web.Models.Catalog;
2+
@using SmartStore.Web.Framework.UI;
3+
@model SearchModel
24
@{
35
Layout = "~/Views/Shared/_ColumnsThree.cshtml";
46

5-
//title
67
Html.AddTitleParts(T("PageTitle.Search").Text);
78
}
8-
@using SmartStore.Core;
9-
@using SmartStore.Core.Infrastructure;
10-
@using SmartStore.Web;
11-
@using SmartStore.Web.Models.Catalog;
12-
@using SmartStore.Web.Framework.UI;
139

1410
@functions{
1511
private bool ShowListOptions() {
@@ -32,7 +28,9 @@
3228
<script type="text/javascript">
3329
$(document).ready(function () {
3430
$("#@Html.FieldIdFor(model => model.As)").click(toggleAdvancedSearch);
35-
toggleAdvancedSearch();
31+
toggleAdvancedSearch();
32+
33+
$('#@Html.FieldIdFor(model => model.Q)').focus();
3634
});
3735
3836
function toggleAdvancedSearch() {

0 commit comments

Comments
 (0)