Skip to content

Commit

Permalink
Update master sources for nopCommerce 4.30
Browse files Browse the repository at this point in the history
  • Loading branch information
iAlexeyProkhorov committed Jun 15, 2020
1 parent bec9591 commit 2bf704e
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 311 deletions.
52 changes: 30 additions & 22 deletions Components/PublicInfoComponent.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Microsoft.AspNetCore.Mvc;
using Nop.Core;
using Nop.Core.Caching;
using Nop.Core.Domain.Customers;
using Nop.Plugin.Widgets.qBoSlider.Extensions;
using Nop.Plugin.Widgets.qBoSlider.Infrastructure.Cache;
using Nop.Plugin.Widgets.qBoSlider.Models;
using Nop.Plugin.Widgets.qBoSlider.Service;
using Nop.Services.Caching;
using Nop.Services.Configuration;
using Nop.Services.Customers;
using Nop.Services.Localization;
using Nop.Services.Media;
using Nop.Services.Security;
Expand All @@ -21,11 +23,13 @@ public class PublicInfoComponent : NopViewComponent
#region Fields

private readonly IAclService _aclService;
private readonly ICacheManager _cacheManager;
private readonly ICacheKeyService _cacheKeyService;
private readonly ICustomerService _customerService;
private readonly ILocalizationService _localizationService;
private readonly IPictureService _pictureService;
private readonly ISettingService _settingService;
private readonly ISlideService _slideService;
private readonly IStaticCacheManager _staticCacheManager;

private readonly IStoreContext _storeContext;
private readonly IWorkContext _workContext;
Expand All @@ -35,20 +39,24 @@ public class PublicInfoComponent : NopViewComponent
#region Constructor

public PublicInfoComponent(IAclService aclService,
ICacheManager cacheManager,
ICacheKeyService cacheKeyService,
ICustomerService customerService,
ILocalizationService localizationService,
IPictureService pictureService,
ISettingService settingService,
ISlideService slideService,
IStaticCacheManager staticCacheManager,
IStoreContext storeContext,
IWorkContext workContext)
{
this._aclService = aclService;
this._cacheManager = cacheManager;
this._cacheKeyService = cacheKeyService;
this._customerService = customerService;
this._localizationService = localizationService;
this._pictureService = pictureService;
this._settingService = settingService;
this._slideService = slideService;
this._staticCacheManager = staticCacheManager;

this._storeContext = storeContext;
this._workContext = workContext;
Expand All @@ -60,41 +68,41 @@ public PublicInfoComponent(IAclService aclService,

public IViewComponentResult Invoke()
{
var qBoSliderSettings = _settingService.LoadSetting<qBoSliderSettings>(_storeContext.CurrentStore.Id);
var settings = _settingService.LoadSetting<qBoSliderSettings>(_storeContext.CurrentStore.Id);
var customer = _workContext.CurrentCustomer;

//1.0.5 all with Alc
var customerRolesList = _workContext.CurrentCustomer.GetCustomerRoleIds().ToList();
var customerRolesString = string.Empty;
foreach (var roleId in customerRolesList)
customerRolesString = string.Format("{0},{1}", customerRolesString, roleId);
customerRolesString = customerRolesString.Remove(0, 1);
var customerRoleIds = _customerService.GetCustomerRoleIds(customer);
var customerRolesString = string.Join(",", customerRoleIds);
//create cache key
var cacheKey = _cacheKeyService.PrepareKeyForDefaultCache(ModelCacheEventConsumer.PICTURE_URL_MODEL_KEY, _workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id, DateTime.UtcNow.ToShortDateString(), customerRolesString);

var model = _cacheManager.Get(string.Format("qbo-slider-publicinfo-{0}-{1}-{2}-{3}", _workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id, DateTime.UtcNow.ToShortDateString(), customerRolesString), () =>
var model = _staticCacheManager.Get(cacheKey, () =>
{
var result = new PublicInfoModel()
{
AutoPlay = qBoSliderSettings.AutoPlay,
AutoPlayInterval = qBoSliderSettings.AutoPlayInterval,
MinDragOffsetToSlide = qBoSliderSettings.MinDragOffsetToSlide,
SlideDuration = qBoSliderSettings.SlideDuration,
SlideSpacing = qBoSliderSettings.SlideSpacing,
ArrowNavigation = qBoSliderSettings.ArrowNavigationDisplay,
BulletNavigation = qBoSliderSettings.BulletNavigationDisplay
AutoPlay = settings.AutoPlay,
AutoPlayInterval = settings.AutoPlayInterval,
MinDragOffsetToSlide = settings.MinDragOffsetToSlide,
SlideDuration = settings.SlideDuration,
SlideSpacing = settings.SlideSpacing,
ArrowNavigation = settings.ArrowNavigationDisplay,
BulletNavigation = settings.BulletNavigationDisplay
};
result.Slides = _slideService.GetAllSlides(storeId: _storeContext.CurrentStore.Id)
.Where(x => x.PublishToday()
//1.0.5 all with Alc
//Set catalogsettings.ignoreacl = True to use ALC
//&& ((customerRolesList.Except(_aclService.GetCustomerRoleIdsWithAccess(x).ToList()).ToList().Count < customerRolesList.Count) || (_aclService.GetCustomerRoleIdsWithAccess(x).ToList().Count == 0)))
//&& ((customerRoleIds.Except(_aclService.GetCustomerRoleIdsWithAccess(x).ToList()).ToList().Count < customerRoleIds.Count) || (_aclService.GetCustomerRoleIdsWithAccess(x).ToList().Count == 0)))
&& (_aclService.Authorize(x)))
.OrderBy(x => x.DisplayOrder).Select(slide =>
{
var id = _localizationService.GetLocalized(slide, z => z.PictureId, _workContext.WorkingLanguage.Id, true, false);
var picture = _pictureService.GetPictureById(id.GetValueOrDefault(0));
var pictureId = _localizationService.GetLocalized(slide, z => z.PictureId, _workContext.WorkingLanguage.Id, true, false);
return new PublicInfoModel.PublicSlideModel()
{
Picture = _pictureService.GetPictureUrl(picture),
Picture = _pictureService.GetPictureUrl(pictureId.GetValueOrDefault(0)),
Description = _localizationService.GetLocalized(slide, z => z.Description, _workContext.WorkingLanguage.Id),
Hyperlink = _localizationService.GetLocalized(slide, z => z.HyperlinkAddress, _workContext.WorkingLanguage.Id)
};
Expand Down
15 changes: 2 additions & 13 deletions Controllers/qBoSliderController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public class qBoSliderController : BasePluginController
{
#region Fields

private readonly ICacheManager _cacheManager;

private readonly IAclService _aclService;
private readonly ICustomerService _customerService;
private readonly ILanguageService _languageService;
Expand All @@ -52,8 +50,7 @@ public class qBoSliderController : BasePluginController

#region Constructor

public qBoSliderController(ICacheManager cacheManager,
IAclService aclService,
public qBoSliderController(IAclService aclService,
ICustomerService customerService,
ILanguageService languageService,
ILocalizationService localizationService,
Expand All @@ -68,9 +65,6 @@ public qBoSliderController(ICacheManager cacheManager,
IStoreContext storeContext,
IWorkContext workContext)
{
ForseDefaultCulture();
this._cacheManager = cacheManager;

this._aclService = aclService;
this._customerService = customerService;
this._languageService = languageService;
Expand All @@ -92,11 +86,6 @@ public qBoSliderController(ICacheManager cacheManager,

#region Utilites

protected virtual void ForseDefaultCulture()
{
CommonHelper.SetTelerikCulture();
}

protected virtual void UpdateSlideLocales(Slide slide, SlideModel model)
{
foreach (var localized in model.Locales)
Expand Down Expand Up @@ -293,7 +282,7 @@ public IActionResult SlideList(SlideSearchModel searchModel)
return new SlideSearchModel.SlideListItemModel()
{
Id = slide.Id,
Picture = _pictureService.GetPictureUrl(picture, 300),
Picture = _pictureService.GetPictureUrl(slide.PictureId.GetValueOrDefault(0), 300),
Hyperlink = slide.HyperlinkAddress,
StartDateUtc = slide.StartDateUtc,
EndDateUtc = slide.EndDateUtc,
Expand Down
23 changes: 23 additions & 0 deletions Data/SchemaMigration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using FluentMigrator;
using Nop.Data.Migrations;
using Nop.Plugin.Widgets.qBoSlider.Domain;

namespace Nop.Plugin.Widgets.qBoSlider.Data
{
[SkipMigrationOnUpdate]
[NopMigration("2020/05/24 15:33:23:6455432", "Widgets.qBoSlider base schema")]
public class SchemaMigration : AutoReversingMigration
{
protected IMigrationManager _migrationManager;

public SchemaMigration(IMigrationManager migrationManager)
{
_migrationManager = migrationManager;
}

public override void Up()
{
_migrationManager.BuildTable<Slide>(Create);
}
}
}
7 changes: 5 additions & 2 deletions Infrastructure/Cache/ModelCacheEventConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ public partial class ModelCacheEventConsumer:
/// Key for caching
/// </summary>
/// <remarks>
/// {0} : picture id
/// {0} : working language id
/// {1} : working store id
/// {2} : short date. Cache key will be actual only one day
/// {3} : customer roles(coma separated)
/// </remarks>
public const string PICTURE_URL_MODEL_KEY = "Nop.plugins.widgets.qBoSlider.pictureurl-{0}";
public static CacheKey PICTURE_URL_MODEL_KEY = new CacheKey("qbo-slider-publicinfo-{0}-{1}-{2}-{3}", PICTURE_URL_PATTERN_KEY);
public const string PICTURE_URL_PATTERN_KEY = "Nop.plugins.widgets.qBoSlider";

private readonly IStaticCacheManager _staticCacheManager;
Expand Down
27 changes: 4 additions & 23 deletions Infrastructure/DependencyRegistrar.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
using Autofac;
using Autofac.Core;
using Nop.Core.Caching;
using Nop.Core.Configuration;
using Nop.Core.Data;
using Nop.Core.Infrastructure;
using Nop.Core.Infrastructure.DependencyManagement;
using Nop.Data;
using Nop.Plugin.Widgets.qBoSlider.Controllers;
using Nop.Plugin.Widgets.qBoSlider.Domain;
using Nop.Plugin.Widgets.qBoSlider.Service;
using Nop.Web.Framework.Infrastructure.Extensions;

namespace Nop.Plugin.Widgets.qBoSlider.Infrastructure
{
/// <summary>
/// Represents plugin dependencies
/// </summary>
public class DependencyRegistrar : IDependencyRegistrar
{
public const string ContextName = "nop_object_context_slide";

public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
{
//data context
builder.RegisterPluginDataContext<qBoSliderContext>(ContextName);

//associate services
//services
builder.RegisterType<SlideService>().As<ISlideService>().InstancePerLifetimeScope();


builder.RegisterType<EfRepository<Slide>>()
.As<IRepository<Slide>>()
.WithParameter(ResolvedParameter.ForNamed<IDbContext>(ContextName))
.InstancePerLifetimeScope();

//cache manager
builder.RegisterType<qBoSliderController>()
.WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"));
}

public int Order
Expand Down
38 changes: 0 additions & 38 deletions Infrastructure/EfStartUpTask.cs

This file was deleted.

9 changes: 6 additions & 3 deletions Infrastructure/RouteProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@

namespace Nop.Plugin.Widgets.qBoSlider
{
/// <summary>
/// Represents plugin routes
/// </summary>
public class RouteProvider: IRouteProvider
{
public void RegisterRoutes(IRouteBuilder routeBuilder)
public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
{
routeBuilder.MapRoute("Nop.Plugin.Widgets.qBoSlider.EditSlidePopup",
endpointRouteBuilder.MapControllerRoute("Nop.Plugin.Widgets.qBoSlider.EditSlidePopup",
"plugins/qboslider/editslide/{id}",
new { controller = "qBoSlider", action = "EditSlidePopup", area = "Admin" });

routeBuilder.MapRoute("Nop.Plugin.Widgets.qBoSlider.CreateSlidePopup",
endpointRouteBuilder.MapControllerRoute("Nop.Plugin.Widgets.qBoSlider.CreateSlidePopup",
"plugins/qboslider/createslide",
new { controller = "qBoSlider", action = "CreateSlidePopup", area = "Admin" });
}
Expand Down
Loading

0 comments on commit 2bf704e

Please sign in to comment.