11using System ;
22using System . Collections . Generic ;
3- using System . Diagnostics ;
43using System . Linq ;
54using System . ServiceModel . Syndication ;
65using System . Web . Mvc ;
98using SmartStore . Core . Domain . Catalog ;
109using SmartStore . Core . Domain . Customers ;
1110using SmartStore . Core . Domain . Media ;
12- using SmartStore . Core . Localization ;
1311using SmartStore . Services ;
1412using SmartStore . Services . Catalog ;
1513using SmartStore . Services . Common ;
3331
3432namespace 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
0 commit comments