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.aspxBasically the categoryId is always null. I don't quite understand why this is the case.