How to make Custom View Engine in NopCommerce 4.3?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 năm cách đây
It seems Andrey M. and team are very lazy to make a complete documentation. I am not able to override view (with another model passed to it - an extended one) for a week. I need to do this in plugin and use my own theme for that.
3 năm cách đây
Hi,

I am also facing same issue, could you please share your solution, how you did this.

I am not able to override view (with another model passed to it - an extended one)  .

Thanks
3 năm cách đây
The solution is to learn MVC, .NET Core and NopCommerce. This is my solution in progress.
3 năm cách đây
lol, thats funny.

I was able to do it, but its not a ideal way still works.
I created same partialview structure using same model, from that view i added jquery to call controller action which returns new view with my extended model. It still needs testing, but may be its useful for someone.
3 năm cách đây
Yes, you are creative, but my task is to do all code in plugin+child theme, no changes in nop's original code.
3 năm cách đây
I also did it in plugin only not in nopcommerce original code.

In plugin project goto-> Infrastructure -> ViewLocationExpander


public class ViewLocationExpander : IViewLocationExpander
    {
        private const string THEME_KEY = "nop.themename";
        public void PopulateValues(ViewLocationExpanderContext context)
        {
            if (context.AreaName?.Equals(AreaNames.Admin) ?? false)
                return;

            var themeContext = (IThemeContext)context.ActionContext.HttpContext.RequestServices.GetService(typeof(IThemeContext));
            context.Values[THEME_KEY] = themeContext.WorkingThemeName;
        }
    

        public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
        {
            if (context.AreaName == "Admin")
            {
                viewLocations = new[] { $"/Plugins/PluginName/Areas/Admin/Views/{context.ControllerName}/{context.ViewName}.cshtml" }.Concat(viewLocations);
            }
            else
            {
                #region public side

                if (!context.Values.TryGetValue(THEME_KEY, out string theme)) return viewLocations;
                if (context.ViewName == "Viewname in NOP.web")
                {
                    viewLocations = new[] {
                            $"~/Plugins/PluginName/Themes/"+theme+"/Views/{path to viewname}",
                            $"~/Plugins/PluginName/Views/{path to viewname}"
                        }
                        .Concat(viewLocations);
                }

                #endregion
                //viewLocations = new[] { $"/Plugins/PluginName/Views/{context.ControllerName}/{context.ViewName}.cshtml" }.Concat(viewLocations);
            }

            return viewLocations;
        }
    }


The above code will redirect the view to plugin view. Now in plugin View use Jquery cal to plugin controller action and return new view with ur model.
3 năm cách đây
After write above code you have to regiser viewLocationExpander in dbstartup file by below code


/// <summary>
        /// Add and configure any of the middleware
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="configuration">Configuration of the application</param>
        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            /// <summary>
            /// Represents object for the configuring plugin DB context on application startup
            /// </summary>
            services.Configure<RazorViewEngineOptions>(options =>
            {
                options.ViewLocationExpanders.Add(new ViewLocationExpander ());
            });
          
        }
3 năm cách đây
Thanks, guys, I think JQuery is an idea!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.