Skip to content

Commit 2bf704e

Browse files
Update master sources for nopCommerce 4.30
1 parent bec9591 commit 2bf704e

15 files changed

+95
-311
lines changed

Components/PublicInfoComponent.cs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using Microsoft.AspNetCore.Mvc;
22
using Nop.Core;
33
using Nop.Core.Caching;
4-
using Nop.Core.Domain.Customers;
54
using Nop.Plugin.Widgets.qBoSlider.Extensions;
5+
using Nop.Plugin.Widgets.qBoSlider.Infrastructure.Cache;
66
using Nop.Plugin.Widgets.qBoSlider.Models;
77
using Nop.Plugin.Widgets.qBoSlider.Service;
8+
using Nop.Services.Caching;
89
using Nop.Services.Configuration;
10+
using Nop.Services.Customers;
911
using Nop.Services.Localization;
1012
using Nop.Services.Media;
1113
using 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
};

Controllers/qBoSliderController.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ public class qBoSliderController : BasePluginController
3030
{
3131
#region Fields
3232

33-
private readonly ICacheManager _cacheManager;
34-
3533
private readonly IAclService _aclService;
3634
private readonly ICustomerService _customerService;
3735
private readonly ILanguageService _languageService;
@@ -52,8 +50,7 @@ public class qBoSliderController : BasePluginController
5250

5351
#region Constructor
5452

55-
public qBoSliderController(ICacheManager cacheManager,
56-
IAclService aclService,
53+
public qBoSliderController(IAclService aclService,
5754
ICustomerService customerService,
5855
ILanguageService languageService,
5956
ILocalizationService localizationService,
@@ -68,9 +65,6 @@ public qBoSliderController(ICacheManager cacheManager,
6865
IStoreContext storeContext,
6966
IWorkContext workContext)
7067
{
71-
ForseDefaultCulture();
72-
this._cacheManager = cacheManager;
73-
7468
this._aclService = aclService;
7569
this._customerService = customerService;
7670
this._languageService = languageService;
@@ -92,11 +86,6 @@ public qBoSliderController(ICacheManager cacheManager,
9286

9387
#region Utilites
9488

95-
protected virtual void ForseDefaultCulture()
96-
{
97-
CommonHelper.SetTelerikCulture();
98-
}
99-
10089
protected virtual void UpdateSlideLocales(Slide slide, SlideModel model)
10190
{
10291
foreach (var localized in model.Locales)
@@ -293,7 +282,7 @@ public IActionResult SlideList(SlideSearchModel searchModel)
293282
return new SlideSearchModel.SlideListItemModel()
294283
{
295284
Id = slide.Id,
296-
Picture = _pictureService.GetPictureUrl(picture, 300),
285+
Picture = _pictureService.GetPictureUrl(slide.PictureId.GetValueOrDefault(0), 300),
297286
Hyperlink = slide.HyperlinkAddress,
298287
StartDateUtc = slide.StartDateUtc,
299288
EndDateUtc = slide.EndDateUtc,

Data/SchemaMigration.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using FluentMigrator;
2+
using Nop.Data.Migrations;
3+
using Nop.Plugin.Widgets.qBoSlider.Domain;
4+
5+
namespace Nop.Plugin.Widgets.qBoSlider.Data
6+
{
7+
[SkipMigrationOnUpdate]
8+
[NopMigration("2020/05/24 15:33:23:6455432", "Widgets.qBoSlider base schema")]
9+
public class SchemaMigration : AutoReversingMigration
10+
{
11+
protected IMigrationManager _migrationManager;
12+
13+
public SchemaMigration(IMigrationManager migrationManager)
14+
{
15+
_migrationManager = migrationManager;
16+
}
17+
18+
public override void Up()
19+
{
20+
_migrationManager.BuildTable<Slide>(Create);
21+
}
22+
}
23+
}

Infrastructure/Cache/ModelCacheEventConsumer.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ public partial class ModelCacheEventConsumer:
1717
/// Key for caching
1818
/// </summary>
1919
/// <remarks>
20-
/// {0} : picture id
20+
/// {0} : working language id
21+
/// {1} : working store id
22+
/// {2} : short date. Cache key will be actual only one day
23+
/// {3} : customer roles(coma separated)
2124
/// </remarks>
22-
public const string PICTURE_URL_MODEL_KEY = "Nop.plugins.widgets.qBoSlider.pictureurl-{0}";
25+
public static CacheKey PICTURE_URL_MODEL_KEY = new CacheKey("qbo-slider-publicinfo-{0}-{1}-{2}-{3}", PICTURE_URL_PATTERN_KEY);
2326
public const string PICTURE_URL_PATTERN_KEY = "Nop.plugins.widgets.qBoSlider";
2427

2528
private readonly IStaticCacheManager _staticCacheManager;

Infrastructure/DependencyRegistrar.cs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,20 @@
11
using Autofac;
2-
using Autofac.Core;
3-
using Nop.Core.Caching;
42
using Nop.Core.Configuration;
5-
using Nop.Core.Data;
63
using Nop.Core.Infrastructure;
74
using Nop.Core.Infrastructure.DependencyManagement;
8-
using Nop.Data;
9-
using Nop.Plugin.Widgets.qBoSlider.Controllers;
10-
using Nop.Plugin.Widgets.qBoSlider.Domain;
115
using Nop.Plugin.Widgets.qBoSlider.Service;
12-
using Nop.Web.Framework.Infrastructure.Extensions;
136

147
namespace Nop.Plugin.Widgets.qBoSlider.Infrastructure
158
{
9+
/// <summary>
10+
/// Represents plugin dependencies
11+
/// </summary>
1612
public class DependencyRegistrar : IDependencyRegistrar
1713
{
18-
public const string ContextName = "nop_object_context_slide";
19-
2014
public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
2115
{
22-
//data context
23-
builder.RegisterPluginDataContext<qBoSliderContext>(ContextName);
24-
25-
//associate services
16+
//services
2617
builder.RegisterType<SlideService>().As<ISlideService>().InstancePerLifetimeScope();
27-
28-
29-
builder.RegisterType<EfRepository<Slide>>()
30-
.As<IRepository<Slide>>()
31-
.WithParameter(ResolvedParameter.ForNamed<IDbContext>(ContextName))
32-
.InstancePerLifetimeScope();
33-
34-
//cache manager
35-
builder.RegisterType<qBoSliderController>()
36-
.WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"));
3718
}
3819

3920
public int Order

Infrastructure/EfStartUpTask.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

Infrastructure/RouteProvider.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44

55
namespace Nop.Plugin.Widgets.qBoSlider
66
{
7+
/// <summary>
8+
/// Represents plugin routes
9+
/// </summary>
710
public class RouteProvider: IRouteProvider
811
{
9-
public void RegisterRoutes(IRouteBuilder routeBuilder)
12+
public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
1013
{
11-
routeBuilder.MapRoute("Nop.Plugin.Widgets.qBoSlider.EditSlidePopup",
14+
endpointRouteBuilder.MapControllerRoute("Nop.Plugin.Widgets.qBoSlider.EditSlidePopup",
1215
"plugins/qboslider/editslide/{id}",
1316
new { controller = "qBoSlider", action = "EditSlidePopup", area = "Admin" });
1417

15-
routeBuilder.MapRoute("Nop.Plugin.Widgets.qBoSlider.CreateSlidePopup",
18+
endpointRouteBuilder.MapControllerRoute("Nop.Plugin.Widgets.qBoSlider.CreateSlidePopup",
1619
"plugins/qboslider/createslide",
1720
new { controller = "qBoSlider", action = "CreateSlidePopup", area = "Admin" });
1821
}

0 commit comments

Comments
 (0)