Overriding other controllers and their routes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
10 years ago
Hi Wooncherk,

I am also faced some problem regarding this,Hope you give me some suggestion.

My Problem is that I am creating a plugin in which I have to override some action in checkout controller and project is also using some third party checkout plugin that also override the  same action .I don't know  what they have actually  did.But My action is not called in my plugin.My override action in plugin is worked only when I have uninstall the single page checkout plugin.But I have to used that plugin also in my project.I have also tested it with giving some highest priority but My override action in plugin doesn't call.

Any quick reply from will be appreciated.

Thanks!!
10 years ago
I can't give comments until I see how your plugin and the 3rd-party plugin works. And if the 3rd-party is closed-source, we can only do trial-and-error to know how it actually works. Not a straightforward thing I would say. :)
9 years ago
Hi there,

I need some help to understand the routing issue for the admin plugin controller.
I have developed a plugin which adds a custom tab to the product tab strip in the admin area.
While my tab loading I should receive the tab content from the controller by request.
I have tied a different urls to get to the controller, but I received 404 error (not found).
Should I change or create routing for my controller?
If yes, please, suggest me how to do it.

The controller name: ProductPricesTabController
The namespace: Nop.Plugin.Admin.ProductPricesTab.Controllers
The method in the controller class I want to reach: GetTabContent()

What url should I provide to the ajax method in order to received the tab content?

Thank you.
9 years ago
Recently i wrote an article to override default localized route. You can check it here.
8 years ago
I'm having some trouble getting this to work.

I have created a custom Strelli.Nop.Controllers.CatalogController inherriting the original Nop.Web.Controllers.CatalogController and implemented an alternate version of Category(int categoryId, CatalogPagingFilteringModel command) using the new keyword to hide the orginal method.

This is the current method signature:
[NopHttpsRequirement(SslRequirement.No)]
        public new ActionResult Category(int categoryId, CatalogPagingFilteringModel command){
....
}



I then created the following RouteProvider:

public class StrelliRouteProvider : IRouteProvider {
        public int Priority => -1111111;
        //default nop routes have priority -1000000,
        //we want to be called later to overwrite the existing routes

        public void RegisterRoutes(RouteCollection routes) {
            routes.Remove(routes["Category"]);
            routes.MapLocalizedRoute(
                "Category",
                "{SeName}",
                new { controller = "Catalog", action = "Category" },
                new[] { "Strelli.Nop.Controllers" }
            );

            
        }
    }


However, my custom Category function never gets called. Instead it keeps inssisting on calling the original function.

What am I doing wrong?
8 years ago
dimitri.troncquo wrote:
I'm having some trouble getting this to work.

I have created a custom Strelli.Nop.Controllers.CatalogController inherriting the original Nop.Web.Controllers.CatalogController and implemented an alternate version of Category(int categoryId, CatalogPagingFilteringModel command) using the new keyword to hide the orginal method.

This is the current method signature:
[NopHttpsRequirement(SslRequirement.No)]
        public new ActionResult Category(int categoryId, CatalogPagingFilteringModel command){
....
}




It appears part of the problem was trying to hijack the Category function by using the 'new' keyword. This does not play nicely with Reflection, so the system was unable to determine which of the functions should be called, the new one or the one in the baseclass.

I solved that part of the problem by creating a new CatalogControler, which inherits Nop.Web.Controllers.BasePublicController instead of Nop.Web.Controllers.CatalogController.
I also have a StrelliCatalogControler which does inherrit Nop.Web.Controllers.CatalogController (as i want to use alot of the functionality that is protected in my custom method).

So it looks something like this:


namespace Strelli.Nop.Controllers {
    public partial class CatalogController : BasePublicController {
        private readonly StrelliCatalogController _catalogController;

        public CatalogController(ICategoryService categoryService,
            IManufacturerService manufacturerService,
            IProductService productService,
            IVendorService vendorService,
            ICategoryTemplateService categoryTemplateService,
            IManufacturerTemplateService manufacturerTemplateService,
            IWorkContext workContext,
            IStoreContext storeContext,
            ITaxService taxService,
            ICurrencyService currencyService,
            IPictureService pictureService,
            ILocalizationService localizationService,
            IPriceCalculationService priceCalculationService,
            IPriceFormatter priceFormatter,
            IWebHelper webHelper,
            ISpecificationAttributeService specificationAttributeService,
            IProductTagService productTagService,
            IGenericAttributeService genericAttributeService,
            IAclService aclService,
            IStoreMappingService storeMappingService,
            IPermissionService permissionService,
            ICustomerActivityService customerActivityService,
            ITopicService topicService,
            IEventPublisher eventPublisher,
            ISearchTermService searchTermService,
            MediaSettings mediaSettings,
            CatalogSettings catalogSettings,
            VendorSettings vendorSettings,
            BlogSettings blogSettings,
            ForumSettings  forumSettings,
            ICacheManager cacheManager)
        {
            _catalogController = new StrelliCatalogController(
                categoryService, manufacturerService, productService, vendorService, categoryTemplateService,
                manufacturerTemplateService, workContext, storeContext, taxService, currencyService,
                pictureService, localizationService, priceCalculationService, priceFormatter, webHelper,
                specificationAttributeService, productTagService, genericAttributeService, aclService,
                storeMappingService, permissionService, customerActivityService, topicService, eventPublisher,
                searchTermService, mediaSettings, catalogSettings, vendorSettings, blogSettings, forumSettings, cacheManager
            );
        }

        [NopHttpsRequirement(SslRequirement.No)]
        public ActionResult Category(int categoryId, CatalogPagingFilteringModel command) {
            return _catalogController.StrelliCategory(categoryId, command);
        }
    }

    public partial class StrelliCatalogController : Nop.Web.Controllers.CatalogController {
        //fields and ctr
        ...
        public ActionResult StrelliCategory(int categoryId, CatalogPagingFilteringModel command) {
            //custom code using the protected methods of Nop.Web.Controllers.CatalogController
        }
    }
}


So far so good I'd say. Only now I am running into a whole new error which is described here:
https://www.nopcommerce.com/boards/t/41064/custom-routing-hijacking-an-existing-route.aspx

Basically the categoryId is always null. I don't quite understand why this is the case.
8 years ago
Silly me. It seems the solution was right under my nose after all. The solution provided here was a perfect fit:

dotnetdreamer wrote:
Recently i wrote an article to override default localized route. You can check it here.


I got sidetracked a bit to far before I realized this works after all.

For a more detailed explanation please check this post.
8 years ago
Silly me. It seems the solution was right under my nose after all. The solution provided here was a perfect fit:

dotnetdreamer wrote:
Recently i wrote an article to override default localized route. You can check it here.


I got sidetracked a bit to far before I realized this works after all.

For a more detailed explanation please check this post.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.