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
Improve components path - allow to use views per themes in the plugin
KrzysztofPajakec18a41b5919
diff --git a/src/Web/Grand.Web.Common/Components/ViewComponentExtensions.cs b/src/Web/Grand.Web.Common/Components/ViewComponentExtensions.csnew file mode 100644index 000000000..2daa27a63--- /dev/null+++ b/src/Web/Grand.Web.Common/Components/ViewComponentExtensions.cs@@ -0,0 +1,27 @@+using Grand.Web.Common.Themes;+using Microsoft.AspNetCore.Mvc;+using Microsoft.AspNetCore.Mvc.ViewEngines;+using Microsoft.Extensions.DependencyInjection;++namespace Grand.Web.Common.Components+{+ public static class ViewComponentExtensions+ {+ public static string GetViewPath(this ViewComponent viewComponent, string viewName = "Default")+ {+ var themeContext = viewComponent.HttpContext.RequestServices.GetService<IThemeContext>();+ var theme = themeContext.WorkingThemeName;++ var viewPath = $"Views/Shared/Components/{viewComponent.ViewComponentContext.ViewComponentDescriptor.ShortName}/{viewName}.cshtml";+ var themeViewPath = $"/Themes/{theme}{viewPath}";+ var viewEngine = viewComponent.ViewContext.HttpContext.RequestServices.GetRequiredService<ICompositeViewEngine>();+ var result = viewEngine.GetView("", themeViewPath, isMainPage: false);+ if (result.Success)+ {+ viewPath = themeViewPath;+ }++ return viewPath;+ }+ }+}