@@ -501,51 +501,6 @@ requirejs(['algoliaBundle'], function(algoliaBundle) {
501
501
$ ( this ) . html ( '+ ' + algoliaConfig . translations . refine ) ;
502
502
} ) ;
503
503
504
- // Handle backward compatibility with old routing
505
- function routingBc ( routeState ) {
506
- // Handle legacy facets
507
- // https://github.com/algolia/algoliasearch-helper-js/blob/39bec1caf24a60acd042eb7bb5d7d7c719fde58b/src/SearchParameters/shortener.js#L6
508
- var legacyFacets = [ "dFR" , "hFR" , "fR" ] ;
509
- for ( i = 0 ; i < legacyFacets . length ; i ++ ) {
510
- if ( routeState [ legacyFacets [ i ] ] ) {
511
- for ( var key in routeState [ legacyFacets [ i ] ] ) {
512
- if ( routeState [ legacyFacets [ i ] ] . hasOwnProperty ( key ) ) {
513
- key == "categories.level0" ?
514
- routeState [ "categories" ] = routeState [ legacyFacets [ i ] ] [ key ] [ 0 ] . split ( ' /// ' ) . join ( '~' ) :
515
- routeState [ key ] = routeState [ legacyFacets [ i ] ] [ key ] . join ( '~' ) ;
516
- }
517
- }
518
- }
519
- }
520
-
521
- // Handle legacy numeric refinements
522
- if ( routeState . nR ) {
523
- for ( var key in routeState . nR ) {
524
- if ( routeState . nR . hasOwnProperty ( key ) ) {
525
- var lt = '' , gt = '' , eq = '' ;
526
- if ( routeState . nR [ key ] [ '=' ] ) {
527
- eq = routeState . nR [ key ] [ '=' ] ;
528
- }
529
- if ( routeState . nR [ key ] [ '<=' ] ) {
530
- lt = routeState . nR [ key ] [ '<=' ] ;
531
- }
532
- if ( routeState . nR [ key ] [ '>=' ] ) {
533
- gt = routeState . nR [ key ] [ '>=' ] ;
534
- }
535
-
536
- if ( eq != '' ) {
537
- routeState [ key ] = eq ;
538
- }
539
- if ( lt != '' || gt != '' ) {
540
- routeState [ key ] = gt + ':' + lt ;
541
- }
542
- }
543
- }
544
- }
545
-
546
- return routeState ;
547
- }
548
-
549
504
// The url is now rendered as follows : http://website.com?q=searchquery&facet1=value&facet2=value1~value2
550
505
// "?" and "&" are used to be fetched easily inside Magento for the backend rendering
551
506
// Multivalued facets use "~" as separator
@@ -579,80 +534,83 @@ requirejs(['algoliaBundle'], function(algoliaBundle) {
579
534
} ) ,
580
535
stateMapping : {
581
536
stateToRoute : function ( uiState ) {
582
- var map = { } ;
537
+ var productIndexName = algoliaConfig . indexName + '_products' ;
538
+ var uiStateProductIndex = uiState [ productIndexName ] || { } ;
539
+ var routeParameters = { } ;
583
540
if ( algoliaConfig . isCategoryPage ) {
584
- map [ 'q' ] = uiState . query ;
541
+ routeParameters [ 'q' ] = uiState [ productIndexName ] . query ;
585
542
} else {
586
- map [ 'q' ] = uiState . query || '__empty__' ;
543
+ routeParameters [ 'q' ] = uiState [ productIndexName ] . query || '__empty__' ;
587
544
}
588
545
if ( algoliaConfig . facets ) {
589
546
for ( var i = 0 ; i < algoliaConfig . facets . length ; i ++ ) {
590
547
var currentFacet = algoliaConfig . facets [ i ] ;
591
548
// Handle refinement facets
592
549
if ( currentFacet . attribute != 'categories' && ( currentFacet . type == 'conjunctive' || currentFacet . type == 'disjunctive' ) ) {
593
- map [ currentFacet . attribute ] = ( uiState . refinementList &&
594
- uiState . refinementList [ currentFacet . attribute ] &&
595
- uiState . refinementList [ currentFacet . attribute ] . join ( '~' ) ) ;
550
+ routeParameters [ currentFacet . attribute ] = ( uiStateProductIndex . refinementList &&
551
+ uiStateProductIndex . refinementList [ currentFacet . attribute ] &&
552
+ uiStateProductIndex . refinementList [ currentFacet . attribute ] . join ( '~' ) ) ;
596
553
}
597
554
// Handle categories
598
555
if ( currentFacet . attribute == 'categories' && ! algoliaConfig . isCategoryPage ) {
599
- map [ currentFacet . attribute ] = ( uiState . hierarchicalMenu &&
600
- uiState . hierarchicalMenu [ currentFacet . attribute + '.level0' ] &&
601
- uiState . hierarchicalMenu [ currentFacet . attribute + '.level0' ] . join ( '~' ) ) ;
556
+ routeParameters [ currentFacet . attribute ] = ( uiStateProductIndex . hierarchicalMenu &&
557
+ uiStateProductIndex . hierarchicalMenu [ currentFacet . attribute + '.level0' ] &&
558
+ uiStateProductIndex . hierarchicalMenu [ currentFacet . attribute + '.level0' ] . join ( '~' ) ) ;
602
559
}
603
560
// Handle sliders
604
561
if ( currentFacet . type == 'slider' ) {
605
- map [ currentFacet . attribute ] = ( uiState . range &&
606
- uiState . range [ currentFacet . attribute ] &&
607
- uiState . range [ currentFacet . attribute ] ) ;
562
+ routeParameters [ currentFacet . attribute ] = ( uiStateProductIndex . range &&
563
+ uiStateProductIndex . range [ currentFacet . attribute ] &&
564
+ uiStateProductIndex . range [ currentFacet . attribute ] ) ;
608
565
}
609
566
} ;
610
567
}
611
- map [ 'sortBy' ] = uiState . sortBy ;
612
- map [ 'page' ] = uiState . page ;
613
- return map ;
568
+ routeParameters [ 'sortBy' ] = uiStateProductIndex . sortBy ;
569
+ routeParameters [ 'page' ] = uiStateProductIndex . page ;
570
+ return routeParameters ;
614
571
} ,
615
- routeToState : function ( routeState ) {
616
- var map = { } ;
617
- routeState = routingBc ( routeState ) ;
618
- map [ 'query' ] = routeState . q == '__empty__' ? '' : routeState . q ;
619
- if ( algoliaConfig . isLandingPage && typeof map [ 'query' ] === 'undefined' && algoliaConfig . landingPage . query != '' ) {
620
- map [ 'query' ] = algoliaConfig . landingPage . query ;
572
+ routeToState : function ( routeParameters ) {
573
+ var productIndexName = algoliaConfig . indexName + '_products' ;
574
+ var uiStateProductIndex = { }
575
+
576
+ uiStateProductIndex [ 'query' ] = routeParameters . q == '__empty__' ? '' : routeParameters . q ;
577
+ if ( algoliaConfig . isLandingPage && typeof uiStateProductIndex [ 'query' ] === 'undefined' && algoliaConfig . landingPage . query != '' ) {
578
+ uiStateProductIndex [ 'query' ] = algoliaConfig . landingPage . query ;
621
579
}
622
580
623
581
var landingPageConfig = algoliaConfig . isLandingPage && algoliaConfig . landingPage . configuration ?
624
582
JSON . parse ( algoliaConfig . landingPage . configuration ) :
625
583
{ } ;
626
584
627
- map [ 'refinementList' ] = { } ;
628
- map [ 'hierarchicalMenu' ] = { } ;
629
- map [ 'range' ] = { } ;
585
+ uiStateProductIndex [ 'refinementList' ] = { } ;
586
+ uiStateProductIndex [ 'hierarchicalMenu' ] = { } ;
587
+ uiStateProductIndex [ 'range' ] = { } ;
630
588
if ( algoliaConfig . facets ) {
631
589
for ( var i = 0 ; i < algoliaConfig . facets . length ; i ++ ) {
632
590
var currentFacet = algoliaConfig . facets [ i ] ;
633
591
// Handle refinement facets
634
592
if ( currentFacet . attribute != 'categories' && ( currentFacet . type == 'conjunctive' || currentFacet . type == 'disjunctive' ) ) {
635
- map [ 'refinementList' ] [ currentFacet . attribute ] = routeState [ currentFacet . attribute ] && routeState [ currentFacet . attribute ] . split ( '~' ) ;
593
+ uiStateProductIndex [ 'refinementList' ] [ currentFacet . attribute ] = routeParameters [ currentFacet . attribute ] && routeParameters [ currentFacet . attribute ] . split ( '~' ) ;
636
594
if ( algoliaConfig . isLandingPage &&
637
- typeof map [ 'refinementList' ] [ currentFacet . attribute ] === 'undefined' &&
595
+ typeof uiStateProductIndex [ 'refinementList' ] [ currentFacet . attribute ] === 'undefined' &&
638
596
currentFacet . attribute in landingPageConfig ) {
639
- map [ 'refinementList' ] [ currentFacet . attribute ] = landingPageConfig [ currentFacet . attribute ] . split ( '~' ) ;
597
+ uiStateProductIndex [ 'refinementList' ] [ currentFacet . attribute ] = landingPageConfig [ currentFacet . attribute ] . split ( '~' ) ;
640
598
}
641
599
}
642
600
// Handle categories facet
643
601
if ( currentFacet . attribute == 'categories' && ! algoliaConfig . isCategoryPage ) {
644
- map [ 'hierarchicalMenu' ] [ 'categories.level0' ] = routeState [ 'categories' ] && routeState [ 'categories' ] . split ( '~' ) ;
602
+ uiStateProductIndex [ 'hierarchicalMenu' ] [ 'categories.level0' ] = routeParameters [ 'categories' ] && routeParameters [ 'categories' ] . split ( '~' ) ;
645
603
if ( algoliaConfig . isLandingPage &&
646
- typeof map [ 'hierarchicalMenu' ] [ 'categories.level0' ] === 'undefined' &&
604
+ typeof uiStateProductIndex [ 'hierarchicalMenu' ] [ 'categories.level0' ] === 'undefined' &&
647
605
'categories.level0' in landingPageConfig ) {
648
- map [ 'hierarchicalMenu' ] [ 'categories.level0' ] = landingPageConfig [ 'categories.level0' ] . split ( ' /// ' ) ;
606
+ uiStateProductIndex [ 'hierarchicalMenu' ] [ 'categories.level0' ] = landingPageConfig [ 'categories.level0' ] . split ( ' /// ' ) ;
649
607
}
650
608
}
651
609
// Handle sliders
652
610
if ( currentFacet . type == 'slider' ) {
653
- map [ 'range' ] [ currentFacet . attribute ] = routeState [ currentFacet . attribute ] && routeState [ currentFacet . attribute ] ;
611
+ uiStateProductIndex [ 'range' ] [ currentFacet . attribute ] = routeParameters [ currentFacet . attribute ] && routeParameters [ currentFacet . attribute ] ;
654
612
if ( algoliaConfig . isLandingPage &&
655
- typeof map [ 'range' ] [ currentFacet . attribute ] === 'undefined' &&
613
+ typeof uiStateProductIndex [ 'range' ] [ currentFacet . attribute ] === 'undefined' &&
656
614
currentFacet . attribute in landingPageConfig ) {
657
615
658
616
var facetValue = '' ;
@@ -663,14 +621,17 @@ requirejs(['algoliaBundle'], function(algoliaBundle) {
663
621
if ( typeof landingPageConfig [ currentFacet . attribute ] [ '<=' ] !== "undefined" ) {
664
622
facetValue += landingPageConfig [ currentFacet . attribute ] [ '<=' ] [ 0 ] ;
665
623
}
666
- map [ 'range' ] [ currentFacet . attribute ] = facetValue ;
624
+ uiStateProductIndex [ 'range' ] [ currentFacet . attribute ] = facetValue ;
667
625
}
668
626
}
669
627
} ;
670
628
}
671
- map [ 'sortBy' ] = routeState . sortBy ;
672
- map [ 'page' ] = routeState . page ;
673
- return map ;
629
+ uiStateProductIndex [ 'sortBy' ] = routeParameters . sortBy ;
630
+ uiStateProductIndex [ 'page' ] = routeParameters . page ;
631
+
632
+ var uiState = { } ;
633
+ uiState [ productIndexName ] = uiStateProductIndex ;
634
+ return uiState ;
674
635
}
675
636
}
676
637
} ;
0 commit comments