Plugin: override admin route

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
10 năm cách đây
Hi,

I've created a plugin that show a list of orders like the default but with extra filters. Now i want to override the default admin route: Admin/Order/List but i can't get this to work. This is my route provider:


    public partial class RouteProvider : IRouteProvider
    {
        public void RegisterRoutes(RouteCollection routes)
        {
           routes.MapRoute("Nop.Plugin.Admin.Orders.List",
                "Admin/Order/List",
                new { controller = "Order", action = "List", orderIds = UrlParameter.Optional },
                new string[] { "Nop.Plugin.Admin.Orders.Controllers" }
            ).DataTokens.Add("Area","Admin");
            
        }

        public int Priority
        {
            get
            {
                return 100;
            }
        }
    }
10 năm cách đây
Hi Nesse,
Try something like:
var route = routes.MapRoute("Nop.Plugin.Admin.Orders.List",
                                          "Admin/Order/List",
                                           new { controller = "Order", action = "List", orderIds = UrlParameter.Optional, area = "Admin"  },
                                           new [] { "Nop.Plugin.Admin.Orders.Controllers" });
            route.DataTokens.Add("area", "admin");
            routes.Remove(route);
            routes.Insert(0, route);
10 năm cách đây
Thank you,
Your solution saved me lots of time.
Yarik
8 năm cách đây
[email protected] wrote:
Hi Nesse,
Try something like:
var route = routes.MapRoute("Nop.Plugin.Admin.Orders.List",
                                          "Admin/Order/List",
                                           new { controller = "Order", action = "List", orderIds = UrlParameter.Optional, area = "Admin"  },
                                           new [] { "Nop.Plugin.Admin.Orders.Controllers" });
            route.DataTokens.Add("area", "admin");
            routes.Remove(route);
            routes.Insert(0, route);


Hi [email protected],

After adding 'route.DataTokens.Add("area", "admin");' it stops overiding the view by my plugin view. It takes the original view from Nop.Admin.

What's the cause, please help me with this.
8 năm cách đây
danger wrote:
Hi Nesse,
Try something like:
var route = routes.MapRoute("Nop.Plugin.Admin.Orders.List",
                                          "Admin/Order/List",
                                           new { controller = "Order", action = "List", orderIds = UrlParameter.Optional, area = "Admin"  },
                                           new [] { "Nop.Plugin.Admin.Orders.Controllers" });
            route.DataTokens.Add("area", "admin");
            routes.Remove(route);
            routes.Insert(0, route);

Hi [email protected],

After adding 'route.DataTokens.Add("area", "admin");' it stops overiding the view by my plugin view. It takes the original view from Nop.Admin.

What's the cause, please help me with this.


try to return your view action like below

public ActionResult List()
{
    return View("~/Plugins/[Your plugin name]/Views/[Your folder name]/List.cshtml");
}
8 năm cách đây
Try the following-

var routeOrderList = routes.MapRoute("Admin.Order.List.MyList",
                           "Admin/Order/List/{orderIds}",
                           new { controller = "Order", action = "MyList", orderIds = UrlParameter.Optional },
                           new[] { "Nop.Plugin.MyPlugin.Controller" });
            routes.Remove(routeOrderList );
            routes.Insert(0, routeOrderList );


Change the Action name of your method from List to any other method as it creates ambiguity between two methods. Also give full path of your view in order to redirect to your page.
6 năm cách đây
hi
i want override view admin/order/list.cshtml in mu plugin but when build confront error down:

Compiler Error Message: CS0103: The name 'EngineContext' does not exist in the current context/////
Source Error:


Line 3:  
Line 4:  @{
Line 5:      var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
Line 6:      var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;
Line 7:      var stores = EngineContext.Current.Resolve<IStoreService>().GetAllStores();
6 năm cách đây
hassantavak wrote:
hi
i want override view admin/order/list.cshtml in mu plugin but when build confront error down:

Compiler Error Message: CS0103: The name 'EngineContext' does not exist in the current context/////
Source Error:


Line 3:  
Line 4:  @{
Line 5:      var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
Line 6:      var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;
Line 7:      var stores = EngineContext.Current.Resolve<IStoreService>().GetAllStores();



You have to add appropriate name space of engine context at top of cshtml page.

For an example -

@using yournamespace
6 năm cách đây
the add namespace to view page but not working
the use code for namespace:@using Nop.Admin.Models.Orders
6 năm cách đây
hassantavak wrote:
the add namespace to view page but not working
the use code for namespace:@using Nop.Admin.Models.Orders


You have to add EngineContext,IStoreService namespace.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.