@@ -339,6 +339,30 @@ var unbxdSearchInit = function(jQuery, Handlebars){
339
339
this . init ( ) ;
340
340
}
341
341
342
+ var isTypeSearch = function isTypeSearch ( type ) {
343
+ return type === "search" ;
344
+ } ;
345
+
346
+ var isTypeBrowse = function isTypeBrowse ( type ) {
347
+ return type === "browse" ;
348
+ } ;
349
+
350
+ var isTypeCategory = function isTypeCategory ( type ) {
351
+ return type === "category" ;
352
+ } ;
353
+
354
+ var isTypeBrowseOrCategory = function isTypeBrowseOrCategory ( type ) {
355
+ return isTypeBrowse ( type ) || isTypeCategory ( type ) ;
356
+ } ;
357
+
358
+ var isCategoryIdPresent = function isCategoryIdPresent ( params ) {
359
+ return ( "categoryId" in params && params . categoryId . trim ( ) . length > 0 ) ;
360
+ } ;
361
+
362
+ var isQueryPresent = function isQueryPresent ( params ) {
363
+ return ( "query" in params && params . query . trim ( ) . length > 0 ) ;
364
+ } ;
365
+
342
366
Handlebars . registerHelper ( 'prepareFacetName' , function ( txt ) {
343
367
txt = txt . replace ( "_fq" , "" ) ;
344
368
return txt . replace ( "_" , " " ) ;
@@ -556,8 +580,10 @@ var unbxdSearchInit = function(jQuery, Handlebars){
556
580
557
581
this . params = finalParams ;
558
582
559
- this . params . categoryId = this . options . type == "browse" && typeof this . options . getCategoryId == "function" ?
560
- this . options . getCategoryId ( ) : ( this . params . categoryId ? this . params . categoryId : "" ) ;
583
+ this . params . categoryId = isTypeBrowseOrCategory ( this . options . type ) &&
584
+ typeof this . options . getCategoryId == 'function'
585
+ ? this . options . getCategoryId ( )
586
+ : this . params . categoryId ? this . params . categoryId : '' ;
561
587
562
588
this . setPage ( "page" in finalParams . extra ? finalParams . extra . page : 1 )
563
589
. setPageSize ( "rows" in finalParams . extra ? finalParams . extra . rows : this . options . pageSize ) ;
@@ -580,9 +606,11 @@ var unbxdSearchInit = function(jQuery, Handlebars){
580
606
if ( typeof this . options . setDefaultFilters == "function" )
581
607
this . setDefaultParams ( this . params ) ;
582
608
583
- if ( ( this . options . type == "search" && "query" in this . params && this . params [ "query" ] . trim ( ) . length > 0 ) ||
584
- ( this . options . type == "browse" && "categoryId" in this . params && this . params [ "categoryId" ] . trim ( ) . length > 0 ) )
585
- this . callResults ( this . paintResultSet ) ;
609
+ if (
610
+ ( isTypeSearch ( this . options . type ) && isQueryPresent ( this . params ) ) ||
611
+ ( isTypeBrowseOrCategory ( this . options . type ) && isCategoryIdPresent ( this . params ) )
612
+ )
613
+ this . callResults ( this . paintResultSet ) ;
586
614
}
587
615
, getClass : function ( object ) {
588
616
return Object . prototype . toString . call ( object ) . match ( / ^ \[ o b j e c t \s ( .* ) \] $ / ) [ 1 ] ;
@@ -1001,7 +1029,11 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1001
1029
return ! this . options . isAutoScroll && this . options . isPagination ;
1002
1030
}
1003
1031
, getHostNPath : function ( ) {
1004
- return "//search.unbxdapi.com/" + this . options . APIKey + "/" + this . options . siteName + "/" + ( this . options . type == "browse" ? "browse" : "search" )
1032
+ var handler = "search" ;
1033
+ if ( isTypeBrowseOrCategory ( this . options . type ) ) {
1034
+ handler = this . options . type ;
1035
+ }
1036
+ return "//search.unbxdapi.com/" + this . options . APIKey + "/" + this . options . siteName + "/" + handler ;
1005
1037
}
1006
1038
, getUrlSubstring : function ( ) {
1007
1039
return window . location . search . substring ( 1 ) || window . location . hash . substring ( 1 ) ;
@@ -1031,6 +1063,8 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1031
1063
url += '&' + this . options . searchQueryParam + '=' + encodeURIComponent ( this . params . query ) ;
1032
1064
} else if ( this . options . type == "browse" && this . params [ 'categoryId' ] != undefined ) {
1033
1065
url += '&category-id=' + encodeURIComponent ( this . params . categoryId ) ;
1066
+ } else if ( isTypeCategory ( this . options . type ) && this . params . categoryId !== undefined ) {
1067
+ url += "&p=" + encodeURIComponent ( this . params . categoryId ) ;
1034
1068
}
1035
1069
1036
1070
for ( var x in this . params . filters ) {
@@ -1310,6 +1344,10 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1310
1344
if ( "category-id" in obj )
1311
1345
params . categoryId = obj [ "category-id" ] ;
1312
1346
1347
+ //lets get categoryId(navigation)
1348
+ if ( "p" in obj )
1349
+ params . categoryId = obj [ "p" ] ;
1350
+
1313
1351
//lets get boost
1314
1352
if ( "boost" in obj )
1315
1353
params . extra . boost = obj . boost ;
@@ -1418,13 +1456,18 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1418
1456
this . productEndIdx = ( this . getPage ( ) * this . getPageSize ( ) <= obj . response . numberOfProducts ) ?
1419
1457
this . getPage ( ) * this . getPageSize ( ) : obj . response . numberOfProducts ;
1420
1458
this . totalPages = Math . ceil ( obj . response . numberOfProducts / this . getPageSize ( ) ) ;
1459
+ var queryParams = {
1460
+ numberOfProducts : obj . response . numberOfProducts
1461
+ , start : this . productStartIdx
1462
+ , end : this . productEndIdx
1463
+ }
1464
+ if ( isTypeCategory ( this . options . type ) ) {
1465
+ queryParams . categoryId = obj . searchMetaData . queryParams . p
1466
+ } else {
1467
+ queryParams . query = obj . searchMetaData . queryParams . q
1468
+ }
1421
1469
1422
- jQuery ( this . options . searchQueryDisplay ) . html ( this . compiledSearchQueryTemp ( {
1423
- query : obj . searchMetaData . queryParams . q
1424
- , numberOfProducts : obj . response . numberOfProducts
1425
- , start : this . productStartIdx
1426
- , end : this . productEndIdx
1427
- } ) ) . show ( ) ;
1470
+ jQuery ( this . options . searchQueryDisplay ) . html ( this . compiledSearchQueryTemp ( queryParams ) ) . show ( ) ;
1428
1471
1429
1472
this . paintSort ( obj ) ;
1430
1473
this . paintPageSize ( obj ) ;
0 commit comments