@@ -7,12 +7,14 @@ define([
77 'uiComponent' ,
88 'Magento_Customer/js/customer-data' ,
99 'jquery' ,
10+ 'underscore' ,
1011 'mage/mage' ,
1112 'mage/decorate'
12- ] , function ( Component , customerData , $ ) {
13+ ] , function ( Component , customerData , $ , _ ) {
1314 'use strict' ;
1415
15- var sidebarInitialized = false ;
16+ var sidebarInitialized = false ,
17+ compareProductsReloaded = false ;
1618
1719 /**
1820 * Initialize sidebar
@@ -31,14 +33,18 @@ define([
3133 initialize : function ( ) {
3234 this . _super ( ) ;
3335 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
3843 ) {
3944 //set count to 0 to prevent "compared products" blocks and count to show with wrong count and items
4045 this . compareProducts ( ) . count = 0 ;
4146 customerData . reload ( [ 'compare-products' ] , false ) ;
47+ compareProductsReloaded = true ;
4248 }
4349 initSidebar ( ) ;
4450 }
0 commit comments