Hello all,
I am creating a plugin in which user can change the route of admin area of create,edit,delete products from admin panel, and want to use my plugin controller path instead of admin path.
Steps which i have done.
Create a plugin for this
1.Create a controller and add all the action methods of admin controller to my plugin.
2.Create a CustumViewEngine.cs file for view path.
namespace Nop.Plugin.Nopex.Test.Infrastructure
{
public class CustomViewEngine : ThemeableRazorViewEngine
{
public CustomViewEngine()
{
ViewLocationFormats = new[] { "~/Plugins/Nopex.Test/Views/{0}.cshtml" };
PartialViewLocationFormats = new[] { "~/Plugins/Nopex.Test/Views/{0}.cshtml" };
}
}
}
3.Create a RouteConfig.cs for Route path
namespace Nop.Plugin.Nopex.Test
{
public class RouteConfig : IRouteProvider
{
public int Priority
{
get { return 0; }
}
public void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute("Plugin.Nopex.Test.Index",
"Test/Index",
new { controller = "Test", action = "Index" },
new[] { "Nop.Plugin.Nopex.Test.Controllers" }
);
routes.MapRoute("Plugin.Nopex.Test.List",
"Test/List",
new { controller = "Test", action = "List" },
new[] { "Nop.Plugin.Nopex.Test.Controllers" }
);
routes.MapRoute("Plugin.Nopex.Test.ProductList",
"Test/ProductList",
new { controller = "Test", action = "ProductList" },
new[] { "Nop.Plugin.Nopex.Test.Controllers" }
);
routes.MapRoute("Plugin.Nopex.Test.GoToSku",
"Test/GoToSku",
new { controller = "Test", action = "GoToSku" },
new[] { "Nop.Plugin.Nopex.Test.Controllers" }
);
routes.MapRoute("Plugin.Nopex.Test.Create",
"Test/Create",
new { controller = "Test", action = "Create" },
new[] { "Nop.Plugin.Nopex.Test.Controllers" }
);
routes.MapRoute("Plugin.Nopex.Test.Edit",
"Test/Edit",
new { controller = "Test", action = "Edit" },
new[] { "Nop.Plugin.Nopex.Test.Controllers" }
);
routes.MapRoute("Plugin.Nopex.Test.Delete",
"Test/Delete",
new { controller = "Test", action = "Delete" },
new[] { "Nop.Plugin.Nopex.Test.Controllers" }
);
routes.MapRoute("Plugin.Nopex.Test.DeleteSelected",
"Test/DeleteSelected",
new { controller = "Test", action = "DeleteSelected" },
new[] { "Nop.Plugin.Nopex.Test.Controllers" }
);
routes.MapRoute("Plugin.Nopex.Test.CopyProduct",
"Test/CopyProduct",
new { controller = "Test", action = "CopyProduct" },
new[] { "Nop.Plugin.Nopex.Test.Controllers" }
);
routes.MapRoute("Plugin.Nopex.Test.CopyProduct",
"Test/CopyProduct",
new { controller = "Test", action = "CopyProduct" },
new[] { "Nop.Plugin.Nopex.Test.Controllers" }
);
ViewEngines.Engines.Insert(0, new CustomViewEngine());
}
}
}
4. Create a TestPlugin.cs file for plugin
namespace Nop.Plugin.Nopex.Test
{
public class TestPlugin : BasePlugin, IAdminMenuPlugin
{
private IWebHelper _webHelper;
private readonly ISettingService _settingService;
public TestPlugin(IWebHelper webHelper, ISettingService settingService)
{
_webHelper = webHelper;
_settingService = settingService;
}
public override void Install()
{
base.Install();
}
public override void Uninstall()
{
base.Uninstall();
}
public bool Authenticate()
{
return true;
}
public void ManageSiteMap(SiteMapNode rootNode)
{
List<SiteMapNode> list = new List<SiteMapNode>();
list.Add(new SiteMapNode { Visible = true, Title = "Index", Url = "/Test/Index" });
list.Add(new SiteMapNode { Visible = true, Title = "List", Url = "/Test/List" });
list.Add(new SiteMapNode { Visible = true, Title = "ProductList", Url = "/Test/ProductList" });
list.Add(new SiteMapNode { Visible = true, Title = "Create", Url = "/Test/Create" });
list.Add(new SiteMapNode { Visible = true, Title = "GoToSku", Url = "/Test/GoToSku" });
list.Add(new SiteMapNode { Visible = true, Title = "Edit", Url = "/Test/Edit" });
list.Add(new SiteMapNode { Visible = true, Title = "Delete", Url = "/Test/Delete" });
list.Add(new SiteMapNode { Visible = true, Title = "DeleteSelected", Url = "/Test/DeleteSelected" });
list.Add(new SiteMapNode { Visible = true, Title = "CopyProduct", Url = "/Test/CopyProduct" });
var menuItem = new SiteMapNode()
{
Visible = true,
Title = "Product offer",
Url = "",
ChildNodes = list
};
var pluginNode = rootNode.ChildNodes.FirstOrDefault(x => x.SystemName == "Third party plugins");
if (pluginNode != null)
pluginNode.ChildNodes.Add(menuItem);
else
rootNode.ChildNodes.Add(menuItem);
}
}
}
But Not able to run it and built it Getting error
Error:- The type 'Nop.Data.IDbContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'Nop.Data, Version=3.8.0.0, Culture=neutral, PublicKeyToken=null'
Please Guide me to build this plugins to override the route of admin product create,delete