Hello community. I'm quiet new to Nop and i'm trying to make my first plugin on 4.20. I want to change Product/_AddToCart view. I already include new view in plugin, write new functionality on that page, but now i'm struggle to override Nop view with my plugin view. Thanks in advance!
I think you want to go to "Presentation\Nop.Web\Views\Product" and search for "ProductTemplate.Simple.cshtml" and "ProductTemplate.Grouped.cshtml". In both cshtml file, you will find "@await Html.PartialAsync("_AddToCart", variant.AddToCart, dataDictAddToCart)".
If you want to replace the view, you can replace that line with your view component.
if you are creating a "IWidgetPlugin" you can call your view component like this:
"@await Component.InvokeAsync("Widget", new { widgetZone = PublicWidgetZones.HomepageTop })"
Just replace the "PublicWidgetZones.HomepageTop" with your WidgetZone Name.
Hello community. I'm quiet new to Nop and i'm trying to make my first plugin on 4.20. I want to change Product/_AddToCart view. I already include new view in plugin, write new functionality on that page, but now i'm struggle to override Nop view with my plugin view. Thanks in advance!
You can use View location expander - IViewLocationExpander for override view from plugin.
Get a reference from - nopCommerce > Presentation > Nop.Web.Framework > Themes > ThemeableViewLocationExpander.cs
If you write 1 Plugin and want to overwrite the file in the View folder. You need to do the following: Add 2 files to your Plugin's Infrastructure folder.
--------------NopStartup.cs------------- using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Nop.Core.Infrastructure;
namespace Nop.Plugin.Components.HomepageCategories.Infrasctructure { /// <summary> /// Represents object for the configuring services on application startup /// </summary> public class NopStartup : INopStartup { /// <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) { services.Configure<RazorViewEngineOptions>(options => { options.ViewLocationExpanders.Add(new HomepageCategoriesViewEngine()); }); }
/// <summary> /// Configure the using of added middleware /// </summary> /// <param name="application">Builder for configuring an application's request pipeline</param> public void Configure(IApplicationBuilder application) { }
/// <summary> /// Gets order of this startup configuration implementation /// </summary> public int Order => int.MaxValue; } }
Hi, this solution works great with the default theme. After installing a Theme that he also overwrites the same View; the theme view wins over mine.
In this case, how should you do it?
ciao, marco
nokia1028 wrote:
Hi,
If you write 1 Plugin and want to overwrite the file in the View folder. You need to do the following: Add 2 files to your Plugin's Infrastructure folder.
--------------NopStartup.cs------------- using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Nop.Core.Infrastructure;
namespace Nop.Plugin.Components.HomepageCategories.Infrasctructure { /// <summary> /// Represents object for the configuring services on application startup /// </summary> public class NopStartup : INopStartup { /// <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) { services.Configure<RazorViewEngineOptions>(options => { options.ViewLocationExpanders.Add(new HomepageCategoriesViewEngine()); }); }
/// <summary> /// Configure the using of added middleware /// </summary> /// <param name="application">Builder for configuring an application's request pipeline</param> public void Configure(IApplicationBuilder application) { }
/// <summary> /// Gets order of this startup configuration implementation /// </summary> public int Order => int.MaxValue; } }