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
Widget slider - add support slide per brand
KrzysztofPajak0585afa31232
diff --git a/src/Plugins/Widgets.Slider/Areas/Admin/Controllers/WidgetsSliderController.cs b/src/Plugins/Widgets.Slider/Areas/Admin/Controllers/WidgetsSliderController.csindex 3dcc331fa..09fd3781e 100644--- a/src/Plugins/Widgets.Slider/Areas/Admin/Controllers/WidgetsSliderController.cs+++ b/src/Plugins/Widgets.Slider/Areas/Admin/Controllers/WidgetsSliderController.cs@@ -1,9 +1,6 @@-using Grand.Business.Catalog.Interfaces.Categories;-using Grand.Business.Catalog.Interfaces.Collections;-using Grand.Business.Common.Extensions;+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;using Grand.Business.Storage.Interfaces;using Grand.Web.Common.Controllers;@@ -17,7 +14,7 @@ using System.Threading.Tasks;using Widgets.Slider.Models;using Widgets.Slider.Services;-namespace Widgets.Slider.Controllers+namespace Widgets.Slider.Areas.Admin.Controllers{[AuthorizeAdmin][Area("Admin")]diff --git a/src/Plugins/Widgets.Slider/Areas/Admin/Views/WidgetsSlider/_CreateOrUpdate.TabInfo.cshtml b/src/Plugins/Widgets.Slider/Areas/Admin/Views/WidgetsSlider/_CreateOrUpdate.TabInfo.cshtmlindex 8054fef73..5fd9ce0bc 100644--- a/src/Plugins/Widgets.Slider/Areas/Admin/Views/WidgetsSlider/_CreateOrUpdate.TabInfo.cshtml+++ b/src/Plugins/Widgets.Slider/Areas/Admin/Views/WidgetsSlider/_CreateOrUpdate.TabInfo.cshtml@@ -9,12 +9,20 @@if (sliderTypeId == @(((int)SliderType.HomePage).ToString())) {$('#pnlCategory').hide();$('#pnlCollection').hide();+ $('#pnlBrand').hide();} else if (sliderTypeId == @(((int)SliderType.Category).ToString())) {$('#pnlCategory').show();$('#pnlCollection').hide();+ $('#pnlBrand').hide();}else if (sliderTypeId == @(((int)SliderType.Collection).ToString())) {$('#pnlCategory').hide();$('#pnlCollection').show();+ $('#pnlBrand').hide();+ }+ else if (sliderTypeId == @(((int)SliderType.Brand).ToString())) {+ $('#pnlCategory').hide();+ $('#pnlCollection').hide();+ $('#pnlBrand').show();}}</script>@@ -120,7 +128,13 @@<span asp-validation-for="CollectionId"></span></div></div>-+ <div class="form-group" id="pnlBrand">+ <admin-label asp-for="BrandId" />+ <div class="col-md-9 col-sm-9">+ <admin-input asp-for="BrandId" />+ <span asp-validation-for="BrandId"></span>+ </div>+ </div><div class="form-group"><admin-label asp-for="DisplayOrder" /><div class="col-md-9 col-sm-9">diff --git a/src/Plugins/Widgets.Slider/Components/WidgetSliderComponent.cs b/src/Plugins/Widgets.Slider/Components/WidgetSliderComponent.csindex b72f26ce0..1d128e04a 100644--- a/src/Plugins/Widgets.Slider/Components/WidgetSliderComponent.cs+++ b/src/Plugins/Widgets.Slider/Components/WidgetSliderComponent.cs@@ -74,6 +74,11 @@ namespace Widgets.Slider.ViewComponentsvar slides = await _sliderService.GetPictureSliders(SliderType.Collection, additionalData.ToString());await PrepareModel(slides, model);}+ if (widgetZone == SliderWidgetDefaults.WidgetZoneBrandPage)+ {+ var slides = await _sliderService.GetPictureSliders(SliderType.Brand, additionalData.ToString());+ await PrepareModel(slides, model);+ }if (!model.Slide.Any())return Content("");diff --git a/src/Plugins/Widgets.Slider/Domain/SliderType.cs b/src/Plugins/Widgets.Slider/Domain/SliderType.csindex 13bb366c7..cec3274c5 100644--- a/src/Plugins/Widgets.Slider/Domain/SliderType.cs+++ b/src/Plugins/Widgets.Slider/Domain/SliderType.cs@@ -6,5 +6,6 @@ namespace Widgets.Slider.DomainHomePage = 0,Category = 1,Collection = 2,+ Brand = 3}}diff --git a/src/Plugins/Widgets.Slider/Infrastructure/Mapper/SliderMapperConfiguration.cs b/src/Plugins/Widgets.Slider/Infrastructure/Mapper/SliderMapperConfiguration.csindex ea1cc4a5b..6377d8036 100644--- a/src/Plugins/Widgets.Slider/Infrastructure/Mapper/SliderMapperConfiguration.cs+++ b/src/Plugins/Widgets.Slider/Infrastructure/Mapper/SliderMapperConfiguration.cs@@ -18,6 +18,9 @@ namespace Widgets.Slider.Infrastructure.Mapperif (model.SliderTypeId == (int)SliderType.Collection)return model.CollectionId;+ if (model.SliderTypeId == (int)SliderType.Brand)+ return model.BrandId;+return "";}protected string GetCategoryId(PictureSlider pictureSlider)@@ -35,6 +38,13 @@ namespace Widgets.Slider.Infrastructure.Mapperreturn "";}+ protected string GetBrandId(PictureSlider pictureSlider)+ {+ if (pictureSlider.SliderTypeId == SliderType.Brand)+ return pictureSlider.ObjectEntry;++ return "";+ }public SliderMapperConfiguration(){@@ -45,6 +55,7 @@ namespace Widgets.Slider.Infrastructure.MapperCreateMap<PictureSlider, SlideModel>().ForMember(dest => dest.CategoryId, mo => mo.MapFrom(x => GetCategoryId(x))).ForMember(dest => dest.CollectionId, mo => mo.MapFrom(x => GetCollectionId(x)))+ .ForMember(dest => dest.BrandId, mo => mo.MapFrom(x => GetBrandId(x))).ForMember(dest => dest.Locales, mo => mo.Ignore());CreateMap<SlideListModel, PictureSlider>()diff --git a/src/Plugins/Widgets.Slider/Models/SlideModel.cs b/src/Plugins/Widgets.Slider/Models/SlideModel.csindex c91988165..88e94301b 100644--- a/src/Plugins/Widgets.Slider/Models/SlideModel.cs+++ b/src/Plugins/Widgets.Slider/Models/SlideModel.cs@@ -1,9 +1,7 @@-using Grand.Web.Common.Localization;+using Grand.Infrastructure.ModelBinding;+using Grand.Infrastructure.Models;using Grand.Web.Common.Link;using Grand.Web.Common.Models;-using Grand.Infrastructure.ModelBinding;-using Grand.Infrastructure.Models;-using Microsoft.AspNetCore.Mvc.Rendering;using System.Collections.Generic;using System.ComponentModel.DataAnnotations;@@ -13,7 +11,7 @@ namespace Widgets.Slider.Models{public SlideModel(){- Locales = new List<SlideLocalizedModel>();+ Locales = new List<SlideLocalizedModel>();}[GrandResourceDisplayName("Widgets.Slider.Name")]public string Name { get; set; }@@ -45,7 +43,7 @@ namespace Widgets.Slider.Models//Store acl[GrandResourceDisplayName("Widgets.Slider.LimitedToStores")][UIHint("Stores")]- public string[] Stores { get; set; }+ public string[] Stores { get; set; }[UIHint("Category")][GrandResourceDisplayName("Widgets.Slider.Category")]@@ -54,6 +52,10 @@ namespace Widgets.Slider.Models[GrandResourceDisplayName("Widgets.Slider.Collection")]public string CollectionId { get; set; }+ [UIHint("Brand")]+ [GrandResourceDisplayName("Widgets.Slider.Brand")]+ public string BrandId { get; set; }+}public partial class SlideLocalizedModel : ILocalizedModelLocaldiff --git a/src/Plugins/Widgets.Slider/SliderWidgetDefaults.cs b/src/Plugins/Widgets.Slider/SliderWidgetDefaults.csindex 4d644f9d7..1b3886908 100644--- a/src/Plugins/Widgets.Slider/SliderWidgetDefaults.cs+++ b/src/Plugins/Widgets.Slider/SliderWidgetDefaults.cs@@ -9,5 +9,6 @@public static string WidgetZoneHomePage => "home_page_top";public static string WidgetZoneCategoryPage => "home_page_category";public static string WidgetZoneCollectionPage => "home_page_collection";+ public static string WidgetZoneBrandPage => "home_page_brand";}}diff --git a/src/Plugins/Widgets.Slider/SliderWidgetPlugin.cs b/src/Plugins/Widgets.Slider/SliderWidgetPlugin.csindex 206224aeb..6d673fabc 100644--- a/src/Plugins/Widgets.Slider/SliderWidgetPlugin.cs+++ b/src/Plugins/Widgets.Slider/SliderWidgetPlugin.cs@@ -114,6 +114,10 @@ namespace Widgets.Sliderawait this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Collection", "Collection");await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Collection.Hint", "Select the collection where slider should appear.");await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Collection.Required", "Collection is required");+ await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Brand", "Brand");+ await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Brand.Hint", "Select the brand where slider should appear.");+ await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Brand.Required", "Brand is required");+await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Name", "Name");await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Name.Hint", "Enter the name of the slider");await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Widgets.Slider.Name.Required", "Name is required");@@ -168,6 +172,9 @@ namespace Widgets.Sliderawait this.DeletePluginTranslationResource(_translationService, _languageService, "Widgets.Slider.Collection");await this.DeletePluginTranslationResource(_translationService, _languageService, "Widgets.Slider.Collection.Hint");await this.DeletePluginTranslationResource(_translationService, _languageService, "Widgets.Slider.Collection.Required");+ await this.DeletePluginTranslationResource(_translationService, _languageService, "Widgets.Slider.Brand");+ await this.DeletePluginTranslationResource(_translationService, _languageService, "Widgets.Slider.Brand.Hint");+ await this.DeletePluginTranslationResource(_translationService, _languageService, "Widgets.Slider.Brand.Required");await this.DeletePluginTranslationResource(_translationService, _languageService, "Widgets.Slider.Name");await this.DeletePluginTranslationResource(_translationService, _languageService, "Widgets.Slider.Name.Hint");await this.DeletePluginTranslationResource(_translationService, _languageService, "Widgets.Slider.Name.Required");diff --git a/src/Plugins/Widgets.Slider/SliderWidgetProvider.cs b/src/Plugins/Widgets.Slider/SliderWidgetProvider.csindex f547722e4..674ab0b2a 100644--- a/src/Plugins/Widgets.Slider/SliderWidgetProvider.cs+++ b/src/Plugins/Widgets.Slider/SliderWidgetProvider.cs@@ -38,7 +38,8 @@ namespace Widgets.Slider{SliderWidgetDefaults.WidgetZoneHomePage,SliderWidgetDefaults.WidgetZoneCategoryPage,- SliderWidgetDefaults.WidgetZoneCollectionPage+ SliderWidgetDefaults.WidgetZoneCollectionPage,+ SliderWidgetDefaults.WidgetZoneBrandPage,});}diff --git a/src/Web/Grand.Web/Views/Shared/_TwoColumns.cshtml b/src/Web/Grand.Web/Views/Shared/_TwoColumns.cshtmlindex fb1eed5e6..064a17ee5 100644--- a/src/Web/Grand.Web/Views/Shared/_TwoColumns.cshtml+++ b/src/Web/Grand.Web/Views/Shared/_TwoColumns.cshtml@@ -29,6 +29,13 @@currentCollectionId = Url.ActionContext.RouteData.Values["collectionId"].ToString();}+ //current brand ID+ string currentBrandId = "";+ if (Url.ActionContext.RouteData.Values["controller"].ToString().Equals("catalog", StringComparison.OrdinalIgnoreCase) &&+ Url.ActionContext.RouteData.Values["action"].ToString().Equals("brand", StringComparison.OrdinalIgnoreCase))+ {+ currentBrandId = Url.ActionContext.RouteData.Values["brandId"].ToString();+ }//current product IDstring currentProductId = "";@@ -58,6 +65,10 @@{@await Component.InvokeAsync("Widget", new { widgetZone = "home_page_collection", additionalData = Model.Id })}+@if (!string.IsNullOrEmpty(currentBrandId))+{+ @await Component.InvokeAsync("Widget", new { widgetZone = "home_page_brand", additionalData = Model.Id })+}<div id="TwoColumns" class="row custom-container mt-3"><div class="d-lg-none d-block"><div class="col-12">