I want to override view of shipping method page. I try all variants and nothing work. Help me please. Thank in advance
I want to override view of shipping method page. I try all variants and nothing work. Help me please. Thank in advance
To overwrite a View in NopCommerce you first need to copy the .cshtml file you want to change into your plugin and do the modifications. Don't forget to set this file as Content and set the Copy to Output Directory property to Copy if Newer or Copy Always.
After that you also have to implement the IViewLocationExpander interface in your plugin. It should look something like this.
public class MyViewLocationExpander : IViewLocationExpander
{
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
if(context.ViewName == "ViewToOverwrite")
{
viewLocations = new[] { "PathToMyCustomView" }.Concat(viewLocations);
}
return viewLocations;
}
public void PopulateValues(ViewLocationExpanderContext context)
{
return;
}
}
The last step is to register your custom view expander for the plugin. You can do this by implementing the INopStartup interface in your plugin. It should look something like this.
public class MyStartup : INopStartup
{
public int Order => int.MaxValue;
public void Configure(IApplicationBuilder application)
{
}
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.Configure<RazorViewEngineOptions>(options =>
{
options.ViewLocationExpanders.Add(new MyViewLocationExpander());
});
}
}
Simple, implement ViewLocaionExpander in your plugin. This will override your view and it will render from plugin's view
Hi I used similar solution to solve this problem. In your RouteProvider.cs
public partial class RouteProvider : IRouteProvider
{
public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
{
endpointRouteBuilder.MapControllerRoute("RedirectPdfPackagingSlip",
"Admin/yourController/yourAction",
new { controller = "Order", action = "PdfPackagingSlip" });
}
}
and to go back to the original method you can use in the controller
if (order.ShippingRateComputationMethodSystemName != "your shipping method SystemName")
return Redirect("~/Admin/Order/PdfPackagingSlip?shipmentId=" + ShipmentId);
I hope this helped