@@ -7,12 +7,14 @@ define([
7
7
'uiComponent' ,
8
8
'Magento_Customer/js/customer-data' ,
9
9
'jquery' ,
10
+ 'underscore' ,
10
11
'mage/mage' ,
11
12
'mage/decorate'
12
- ] , function ( Component , customerData , $ ) {
13
+ ] , function ( Component , customerData , $ , _ ) {
13
14
'use strict' ;
14
15
15
- var sidebarInitialized = false ;
16
+ var sidebarInitialized = false ,
17
+ compareProductsReloaded = false ;
16
18
17
19
/**
18
20
* Initialize sidebar
@@ -31,14 +33,18 @@ define([
31
33
initialize : function ( ) {
32
34
this . _super ( ) ;
33
35
this . compareProducts = customerData . get ( 'compare-products' ) ;
34
- if ( window . checkout &&
35
- window . checkout . websiteId &&
36
- window . checkout . websiteId !== this . compareProducts ( ) . websiteId
37
- // TODO this code is only needed if websites share same domain (store code in url)
36
+ if ( ! compareProductsReloaded
37
+ && ! _ . isEmpty ( this . compareProducts ( ) )
38
+ //Expired section names are reloaded on page load
39
+ && _ . indexOf ( customerData . getExpiredSectionNames ( ) , 'compare-products' ) === - 1
40
+ && window . checkout
41
+ && window . checkout . websiteId
42
+ && window . checkout . websiteId !== this . compareProducts ( ) . websiteId
38
43
) {
39
44
//set count to 0 to prevent "compared products" blocks and count to show with wrong count and items
40
45
this . compareProducts ( ) . count = 0 ;
41
46
customerData . reload ( [ 'compare-products' ] , false ) ;
47
+ compareProductsReloaded = true ;
42
48
}
43
49
initSidebar ( ) ;
44
50
}
0 commit comments