Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Plugin - Widget.Slider - allow to limited slides for customer group / stores
KrzysztofPajak1c455e21a569
diff --git a/src/Plugins/Widgets.Slider/Controllers/WidgetsSliderController.cs b/src/Plugins/Widgets.Slider/Controllers/WidgetsSliderController.csindex c0cc219dd..37133f1df 100644--- a/src/Plugins/Widgets.Slider/Controllers/WidgetsSliderController.cs+++ b/src/Plugins/Widgets.Slider/Controllers/WidgetsSliderController.cs@@ -1,6 +1,7 @@using Grand.Business.Catalog.Interfaces.Categories;using Grand.Business.Catalog.Interfaces.Collections;using Grand.Business.Common.Extensions;+using Grand.Business.Common.Interfaces.Configuration;using Grand.Business.Common.Interfaces.Localization;using Grand.Business.Common.Interfaces.Stores;using Grand.Business.Common.Services.Security;@@ -10,8 +11,6 @@ using Grand.Web.Common.DataSource;using Grand.Web.Common.Filters;using Grand.Web.Common.Security.Authorization;using Microsoft.AspNetCore.Mvc;-using Microsoft.AspNetCore.Mvc.Rendering;-using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;@@ -32,6 +31,8 @@ namespace Widgets.Slider.Controllersprivate readonly ILanguageService _languageService;private readonly ICategoryService _categoryService;private readonly ICollectionService _collectionService;+ private readonly SliderWidgetSettings _sliderWidgetSettings;+ private readonly ISettingService _settingService;public WidgetsSliderController(IStoreService storeService,@@ -40,7 +41,9 @@ namespace Widgets.Slider.ControllersISliderService sliderService,ILanguageService languageService,ICategoryService categoryService,- ICollectionService collectionService)+ ICollectionService collectionService,+ ISettingService settingService,+ SliderWidgetSettings sliderWidgetSettings){_storeService = storeService;_pictureService = pictureService;@@ -49,10 +52,26 @@ namespace Widgets.Slider.Controllers_languageService = languageService;_categoryService = categoryService;_collectionService = collectionService;- }+ _settingService = settingService;+ _sliderWidgetSettings = sliderWidgetSettings;+ }public IActionResult Configure(){- return View("~/Plugins/Widgets.Slider/Views/List.cshtml");+ var model = new ConfigurationModel();+ model.DisplayOrder = _sliderWidgetSettings.DisplayOrder;+ model.CustomerGroups = _sliderWidgetSettings.LimitedToGroups?.ToArray();+ model.Stores = _sliderWidgetSettings.LimitedToStores?.ToArray();+ return View("~/Plugins/Widgets.Slider/Views/List.cshtml", model);+ }++ [HttpPost]+ public IActionResult Configure(ConfigurationModel model)+ {+ _sliderWidgetSettings.DisplayOrder = model.DisplayOrder;+ _sliderWidgetSettings.LimitedToGroups = model.CustomerGroups == null ? new List<string>() : model.CustomerGroups.ToList();+ _sliderWidgetSettings.LimitedToStores = model.Stores == null ? new List<string>() : model.Stores.ToList();+ _settingService.SaveSetting(_sliderWidgetSettings);+ return Json("Ok");}[HttpPost]@@ -71,8 +90,7 @@ namespace Widgets.Slider.Controllers}items.Add(model);}- var gridModel = new DataSourceResult- {+ var gridModel = new DataSourceResult {Data = items,Total = sliders.Count};@@ -84,7 +102,7 @@ namespace Widgets.Slider.Controllersvar model = new SlideModel();//localesawait AddLocales(_languageService, model.Locales);-+return View("~/Plugins/Widgets.Slider/Views/Create.cshtml", model);}[HttpPost, ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]@@ -118,7 +136,7 @@ namespace Widgets.Slider.Controllerslocale.Name = slide.GetTranslation(x => x.Name, languageId, false);locale.Description = slide.GetTranslation(x => x.Description, languageId, false);});-+return View("~/Plugins/Widgets.Slider/Views/Edit.cshtml", model);}@@ -137,7 +155,7 @@ namespace Widgets.Slider.ControllersSuccess(_translationService.GetResource("Widgets.Slider.Edited"));return continueEditing ? RedirectToAction("Edit", new { id = pictureSlider.Id }) : RedirectToAction("Configure");- }+ }return View("~/Plugins/Widgets.Slider/Views/Edit.cshtml", model);}diff --git a/src/Plugins/Widgets.Slider/Models/ConfigurationModel.cs b/src/Plugins/Widgets.Slider/Models/ConfigurationModel.csnew file mode 100644index 000000000..4eae05adb--- /dev/null+++ b/src/Plugins/Widgets.Slider/Models/ConfigurationModel.cs@@ -0,0 +1,22 @@+using Grand.Infrastructure.ModelBinding;+using Grand.Infrastructure.Models;+using System.ComponentModel.DataAnnotations;++namespace Widgets.Slider.Models+{+ public class ConfigurationModel : BaseModel+ {++ [GrandResourceDisplayName("Widgets.Slider.Fields.DisplayOrder")]+ public int DisplayOrder { get; set; }++ [UIHint("CustomerGroups")]+ [GrandResourceDisplayName("Widgets.Slider.Fields.LimitedToGroups")]+ public string[] CustomerGroups { get; set; }++ //Store acl+ [GrandResourceDisplayName("Widgets.Slider.Fields.LimitedToStores")]+ [UIHint("Stores")]+ public string[] Stores { get; set; }+ }+}\ No newline at end of filediff --git a/src/Plugins/Widgets.Slider/SliderWidgetPlugin.cs b/src/Plugins/Widgets.Slider/SliderWidgetPlugin.csindex bb9966101..206224aeb 100644--- a/src/Plugins/Widgets.Slider/SliderWidgetPlugin.cs+++ b/src/Plugins/Widgets.Slider/SliderWidgetPlugin.cs@@ -77,6 +77,9 @@ namespace Widgets.Sliderawait _pictureSliderRepository.InsertAsync(pictureSlider2);+ await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Fields.DisplayOrder", "Display order");+ await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Fields.LimitedToGroups", "Limited to groups");+ await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Fields.LimitedToStores", "Limited to stores");await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.FriendlyName", "Widget Slider");diff --git a/src/Plugins/Widgets.Slider/SliderWidgetProvider.cs b/src/Plugins/Widgets.Slider/SliderWidgetProvider.csindex 30148d19e..239900dd8 100644--- a/src/Plugins/Widgets.Slider/SliderWidgetProvider.cs+++ b/src/Plugins/Widgets.Slider/SliderWidgetProvider.cs@@ -24,9 +24,9 @@ namespace Widgets.Sliderpublic int Priority => _sliderWidgetSettings.DisplayOrder;- public IList<string> LimitedToStores => new List<string>();+ public IList<string> LimitedToStores => _sliderWidgetSettings.LimitedToStores;- public IList<string> LimitedToGroups => new List<string>();+ public IList<string> LimitedToGroups => _sliderWidgetSettings.LimitedToGroups;/// <summary>/// Gets widget zones where this widget should be rendereddiff --git a/src/Plugins/Widgets.Slider/SliderWidgetSettings.cs b/src/Plugins/Widgets.Slider/SliderWidgetSettings.csindex a8a0c9ed8..d22ebed00 100644--- a/src/Plugins/Widgets.Slider/SliderWidgetSettings.cs+++ b/src/Plugins/Widgets.Slider/SliderWidgetSettings.cs@@ -1,9 +1,18 @@using Grand.Domain.Configuration;+using System.Collections.Generic;namespace Widgets.Slider{public class SliderWidgetSettings : ISettings{+ public SliderWidgetSettings()+ {+ LimitedToStores = new List<string>();+ LimitedToGroups = new List<string>();+ }public int DisplayOrder { get; set; }+ public IList<string> LimitedToStores { get; set; }++ public IList<string> LimitedToGroups { get; set; }}}diff --git a/src/Plugins/Widgets.Slider/Views/List.cshtml b/src/Plugins/Widgets.Slider/Views/List.cshtmlindex eec3414a1..111249f67 100644--- a/src/Plugins/Widgets.Slider/Views/List.cshtml+++ b/src/Plugins/Widgets.Slider/Views/List.cshtml@@ -1,4 +1,4 @@-+@model ConfigurationModel@inject AdminAreaSettings adminAreaSettings@{Layout = "_ConfigurePlugin";@@ -23,6 +23,9 @@<div class="x_content"><div id="slider-grid"></div></div>+ <div class="x_content form">+ <partial name="~/Plugins/Widgets.Slider/Views/_Settings.cshtml" model="Model"/>+ </div></div></div></div>diff --git a/src/Plugins/Widgets.Slider/Views/_Settings.cshtml b/src/Plugins/Widgets.Slider/Views/_Settings.cshtmlnew file mode 100644index 000000000..dfdea55a4--- /dev/null+++ b/src/Plugins/Widgets.Slider/Views/_Settings.cshtml@@ -0,0 +1,63 @@+@model ConfigurationModel++@inject Widgets.Slider.SliderWidgetSettings setting++<form method="post" id="widget-settings-form">+ <div class="panel-group">+ <div class="panel panel-default">+ <div class="panel-body">+ <div class="form-body">+ <div class="form-group">+ <div class="col-md-3 col-sm-3 text-right">+ <admin-label asp-for="DisplayOrder" class="control-label" />+ </div>+ <div class="col-md-9 col-sm-9">+ <admin-input asp-for="DisplayOrder" />+ </div>+ </div>+ <div class="form-group">+ <admin-label asp-for="CustomerGroups" />+ <div class="col-md-9 col-sm-9">+ <admin-input asp-for="CustomerGroups" />+ <span asp-validation-for="CustomerGroups"></span>+ </div>+ </div>+ <div class="form-group">+ <admin-label asp-for="Stores" />+ <div class="col-md-9 col-sm-9">+ <admin-input asp-for="Stores" />+ <span asp-validation-for="Stores"></span>+ </div>+ </div>+ <div class="form-group">+ <input type="button" id="savegeneralsettings" class="btn default" value="@Loc["Admin.Common.Save"]" />+ <script>+ $(function () {+ $('#savegeneralsettings').click(function () {++ var postData = $(this.form).serialize();+ addAntiForgeryToken(postData);++ $.ajax({+ cache: false,+ type: 'POST',+ url: '@Url.Action("Configure", "WidgetsSlider")',+ data: postData,+ dataType: 'json',+ success: function (data) {+ alert('Saved');+ },+ error: function (xhr, ajaxOptions, thrownError) {+ alert('Failed to add record.');+ }+ });+ return false;+ });+ });+ </script>+ </div>+ </div>+ </div>+ </div>+ </div>+</form>\ No newline at end of filediff --git a/src/Plugins/Widgets.Slider/Widgets.Slider.csproj b/src/Plugins/Widgets.Slider/Widgets.Slider.csprojindex 3196ddeb1..2a3d868bf 100644--- a/src/Plugins/Widgets.Slider/Widgets.Slider.csproj+++ b/src/Plugins/Widgets.Slider/Widgets.Slider.csproj@@ -91,6 +91,9 @@<None Update="Views\_CreateOrUpdate.TabInfo.cshtml"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></None>+ <None Update="Views\_Settings.cshtml">+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>+ </None><None Update="Views\_ViewImports.cshtml"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></None>