11using Microsoft . AspNetCore . Mvc ;
22using Nop . Core ;
33using Nop . Core . Caching ;
4- using Nop . Core . Domain . Customers ;
54using Nop . Plugin . Widgets . qBoSlider . Extensions ;
5+ using Nop . Plugin . Widgets . qBoSlider . Infrastructure . Cache ;
66using Nop . Plugin . Widgets . qBoSlider . Models ;
77using Nop . Plugin . Widgets . qBoSlider . Service ;
8+ using Nop . Services . Caching ;
89using Nop . Services . Configuration ;
10+ using Nop . Services . Customers ;
911using Nop . Services . Localization ;
1012using Nop . Services . Media ;
1113using Nop . Services . Security ;
@@ -21,11 +23,13 @@ public class PublicInfoComponent : NopViewComponent
2123 #region Fields
2224
2325 private readonly IAclService _aclService ;
24- private readonly ICacheManager _cacheManager ;
26+ private readonly ICacheKeyService _cacheKeyService ;
27+ private readonly ICustomerService _customerService ;
2528 private readonly ILocalizationService _localizationService ;
2629 private readonly IPictureService _pictureService ;
2730 private readonly ISettingService _settingService ;
2831 private readonly ISlideService _slideService ;
32+ private readonly IStaticCacheManager _staticCacheManager ;
2933
3034 private readonly IStoreContext _storeContext ;
3135 private readonly IWorkContext _workContext ;
@@ -35,20 +39,24 @@ public class PublicInfoComponent : NopViewComponent
3539 #region Constructor
3640
3741 public PublicInfoComponent ( IAclService aclService ,
38- ICacheManager cacheManager ,
42+ ICacheKeyService cacheKeyService ,
43+ ICustomerService customerService ,
3944 ILocalizationService localizationService ,
4045 IPictureService pictureService ,
4146 ISettingService settingService ,
4247 ISlideService slideService ,
48+ IStaticCacheManager staticCacheManager ,
4349 IStoreContext storeContext ,
4450 IWorkContext workContext )
4551 {
4652 this . _aclService = aclService ;
47- this . _cacheManager = cacheManager ;
53+ this . _cacheKeyService = cacheKeyService ;
54+ this . _customerService = customerService ;
4855 this . _localizationService = localizationService ;
4956 this . _pictureService = pictureService ;
5057 this . _settingService = settingService ;
5158 this . _slideService = slideService ;
59+ this . _staticCacheManager = staticCacheManager ;
5260
5361 this . _storeContext = storeContext ;
5462 this . _workContext = workContext ;
@@ -60,41 +68,41 @@ public PublicInfoComponent(IAclService aclService,
6068
6169 public IViewComponentResult Invoke ( )
6270 {
63- var qBoSliderSettings = _settingService . LoadSetting < qBoSliderSettings > ( _storeContext . CurrentStore . Id ) ;
71+ var settings = _settingService . LoadSetting < qBoSliderSettings > ( _storeContext . CurrentStore . Id ) ;
72+ var customer = _workContext . CurrentCustomer ;
6473
6574 //1.0.5 all with Alc
66- var customerRolesList = _workContext . CurrentCustomer . GetCustomerRoleIds ( ) . ToList ( ) ;
67- var customerRolesString = string . Empty ;
68- foreach ( var roleId in customerRolesList )
69- customerRolesString = string . Format ( "{0},{1}" , customerRolesString , roleId ) ;
70- customerRolesString = customerRolesString . Remove ( 0 , 1 ) ;
75+ var customerRoleIds = _customerService . GetCustomerRoleIds ( customer ) ;
76+ var customerRolesString = string . Join ( "," , customerRoleIds ) ;
77+ //create cache key
78+ var cacheKey = _cacheKeyService . PrepareKeyForDefaultCache ( ModelCacheEventConsumer . PICTURE_URL_MODEL_KEY , _workContext . WorkingLanguage . Id , _storeContext . CurrentStore . Id , DateTime . UtcNow . ToShortDateString ( ) , customerRolesString ) ;
7179
72- var model = _cacheManager . Get ( string . Format ( "qbo-slider-publicinfo-{0}-{1}-{2}-{3}" , _workContext . WorkingLanguage . Id , _storeContext . CurrentStore . Id , DateTime . UtcNow . ToShortDateString ( ) , customerRolesString ) , ( ) =>
80+ var model = _staticCacheManager . Get ( cacheKey , ( ) =>
7381 {
7482 var result = new PublicInfoModel ( )
7583 {
76- AutoPlay = qBoSliderSettings . AutoPlay ,
77- AutoPlayInterval = qBoSliderSettings . AutoPlayInterval ,
78- MinDragOffsetToSlide = qBoSliderSettings . MinDragOffsetToSlide ,
79- SlideDuration = qBoSliderSettings . SlideDuration ,
80- SlideSpacing = qBoSliderSettings . SlideSpacing ,
81- ArrowNavigation = qBoSliderSettings . ArrowNavigationDisplay ,
82- BulletNavigation = qBoSliderSettings . BulletNavigationDisplay
84+ AutoPlay = settings . AutoPlay ,
85+ AutoPlayInterval = settings . AutoPlayInterval ,
86+ MinDragOffsetToSlide = settings . MinDragOffsetToSlide ,
87+ SlideDuration = settings . SlideDuration ,
88+ SlideSpacing = settings . SlideSpacing ,
89+ ArrowNavigation = settings . ArrowNavigationDisplay ,
90+ BulletNavigation = settings . BulletNavigationDisplay
8391 } ;
8492
8593 result . Slides = _slideService . GetAllSlides ( storeId : _storeContext . CurrentStore . Id )
8694 . Where ( x => x . PublishToday ( )
8795 //1.0.5 all with Alc
8896 //Set catalogsettings.ignoreacl = True to use ALC
89- //&& ((customerRolesList .Except(_aclService.GetCustomerRoleIdsWithAccess(x).ToList()).ToList().Count < customerRolesList .Count) || (_aclService.GetCustomerRoleIdsWithAccess(x).ToList().Count == 0)))
97+ //&& ((customerRoleIds .Except(_aclService.GetCustomerRoleIdsWithAccess(x).ToList()).ToList().Count < customerRoleIds .Count) || (_aclService.GetCustomerRoleIdsWithAccess(x).ToList().Count == 0)))
9098 && ( _aclService . Authorize ( x ) ) )
9199 . OrderBy ( x => x . DisplayOrder ) . Select ( slide =>
92100 {
93- var id = _localizationService . GetLocalized ( slide , z => z . PictureId , _workContext . WorkingLanguage . Id , true , false ) ;
94- var picture = _pictureService . GetPictureById ( id . GetValueOrDefault ( 0 ) ) ;
101+ var pictureId = _localizationService . GetLocalized ( slide , z => z . PictureId , _workContext . WorkingLanguage . Id , true , false ) ;
102+
95103 return new PublicInfoModel . PublicSlideModel ( )
96104 {
97- Picture = _pictureService . GetPictureUrl ( picture ) ,
105+ Picture = _pictureService . GetPictureUrl ( pictureId . GetValueOrDefault ( 0 ) ) ,
98106 Description = _localizationService . GetLocalized ( slide , z => z . Description , _workContext . WorkingLanguage . Id ) ,
99107 Hyperlink = _localizationService . GetLocalized ( slide , z => z . HyperlinkAddress , _workContext . WorkingLanguage . Id )
100108 } ;
0 commit comments