I have problem with overriding controller and view with a plugin in nopCommerce 4.0
I want to override CategoryController and replace the _CreateOrUpdate.Info.cshtml view with _CreateOrUpdateCustom.Info.cshtml view.
Here is my controller and routes:
[Area(AreaNames.Admin)]
public partial class CustomCategoryController : Nop.Web.Areas.Admin.Controllers.CategoryController
{
#region Fields
private readonly ICategoryService _categoryService;
private readonly ICategoryTemplateService _categoryTemplateService;
private readonly IManufacturerService _manufacturerService;
private readonly IProductService _productService;
private readonly ICustomerService _customerService;
private readonly IUrlRecordService _urlRecordService;
private readonly IPictureService _pictureService;
private readonly ILanguageService _languageService;
private readonly ILocalizationService _localizationService;
private readonly ILocalizedEntityService _localizedEntityService;
private readonly IDiscountService _discountService;
private readonly IPermissionService _permissionService;
private readonly IAclService _aclService;
private readonly IStoreService _storeService;
private readonly IStoreMappingService _storeMappingService;
private readonly IExportManager _exportManager;
private readonly ICustomerActivityService _customerActivityService;
private readonly IVendorService _vendorService;
private readonly CatalogSettings _catalogSettings;
private readonly IWorkContext _workContext;
private readonly IImportManager _importManager;
private readonly IStaticCacheManager _cacheManager;
private readonly IErpCategoryService _erpCategoryService;
private IRepository<ErpCategory> _erpCategory;
#endregion
#region Constructors
public CustomCategoryController(ICategoryService categoryService, ICategoryTemplateService categoryTemplateService,
IManufacturerService manufacturerService, IProductService productService,
ICustomerService customerService,
IUrlRecordService urlRecordService,
IPictureService pictureService,
ILanguageService languageService,
ILocalizationService localizationService,
ILocalizedEntityService localizedEntityService,
IDiscountService discountService,
IPermissionService permissionService,
IAclService aclService,
IStoreService storeService,
IStoreMappingService storeMappingService,
IExportManager exportManager,
IVendorService vendorService,
ICustomerActivityService customerActivityService,
CatalogSettings catalogSettings,
IWorkContext workContext,
IImportManager importManager,
IStaticCacheManager cacheManager,
IErpCategoryService erpCategoryService,
IRepository<ErpCategory> erpCategory)
: base(categoryService, categoryTemplateService, manufacturerService, productService, customerService, urlRecordService, pictureService,
languageService, localizationService, localizedEntityService, discountService, permissionService, aclService, storeService, storeMappingService,
exportManager, vendorService, customerActivityService, catalogSettings, workContext, importManager, cacheManager)
{
this._categoryService = categoryService;
this._categoryTemplateService = categoryTemplateService;
this._manufacturerService = manufacturerService;
this._productService = productService;
this._customerService = customerService;
this._urlRecordService = urlRecordService;
this._pictureService = pictureService;
this._languageService = languageService;
this._localizationService = localizationService;
this._localizedEntityService = localizedEntityService;
this._discountService = discountService;
this._permissionService = permissionService;
this._vendorService = vendorService;
this._aclService = aclService;
this._storeService = storeService;
this._storeMappingService = storeMappingService;
this._exportManager = exportManager;
this._customerActivityService = customerActivityService;
this._catalogSettings = catalogSettings;
this._workContext = workContext;
this._importManager = importManager;
this._cacheManager = cacheManager;
this._erpCategoryService = erpCategoryService;
this._erpCategory = erpCategory;
}
#endregion
#region Create / Edit / Delete
[ActionName("CustomCreate")]
new public IActionResult Create()
{
var model = new AdminCategoryModel();
//default values
model.ErpCategoryId = "";
IActionResult actionResult = base.Create();
return View("Create", ((ViewResult)actionResult).Model);
}
[ActionName("CustomCreate")]
[HttpPost, ParameterBasedOnFormName("save-continue", "continueEditing")]
public IActionResult Create(AdminCategoryModel model, bool continueEditing)
{
if (ModelState.IsValid)
{
var category = model.ToEntity();
var nextId = _erpCategoryService.GetTableId();
if (model.ErpCategoryId != null)
{
// Setup the product to save
var record = new ErpCategory();
record.CategoryId = nextId.GetValueOrDefault() + 1;
record.ErpCategoryId = model.ErpCategoryId;
// Map the values we're interested in to our new entity
_erpCategoryService.InsertErpCategory(record);
}
IActionResult actionResult = base.Create(model, continueEditing);
if (continueEditing)
{
//selected tab
SaveSelectedTabName();
return RedirectToAction("Edit", new { id = nextId.GetValueOrDefault() + 1 });
}
return RedirectToAction("List");
}
return View("Create", model);
}
}
This is the RouteProvider.cs from the plugin:
public partial class RouteProvider : IRouteProvider
{
public void RegisterRoutes(IRouteBuilder routes)
{
routes.MapAreaRoute(
name: "Nop.Plugin.Misc.EsoftErpConnector.CreateOrUpdate",
areaName: AreaNames.Admin,
template: "Admin/Category/Create",
defaults: new { controller = "CustomCategory", action = "CustomCreate" }
);
}
public int Priority
{
get { return -1; } // I try with 1 but that is not working to
}
}
Any help would be more than welcome :)