Plugin: override admin route

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
10 years ago
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 years ago
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 years ago
Thank you,
Your solution saved me lots of time.
Yarik
8 years ago
[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 years ago
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 years ago
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 years ago
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 years ago
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 years ago
the add namespace to view page but not working
the use code for namespace:@using Nop.Admin.Models.Orders
6 years ago
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.