How to override "/Admin/Product/Create" route?

5 days ago
Hi. I'm developing a nopCommerce (v4.70) plugin, and now I have to register a custom route to override the native route "/Admin/Product/Create". In "RouteProvider" class there is no static route for this. I did some analisies and I think there is no generic route related to this particular route as well.

If I knew at least the route' name is would be really helpful. Because the controller is "Product" and the action is "Create".

Does anybody here knows how to do that? Any clue?

Thanks in advance.
4 days ago
The above is done via controller actions
One way is to follow similar methods as for Product Create
The form is "/Admin/Product/Create" = Admin Area / Controller / Action
So in the view
<form asp-controller="Product" asp-action="Create" method="post" id="product-form">

In your view you can assign a different action if using the same controller

Or depending on what you are planning
You ca also have a new view called from a different menu option
And use the same action in a new controller
4 days ago
I'm not positive in this case, but in many cases you can override routes using controller attributes:
[HttpPost("Admin/Product/Create")]
public async Task<IActionResult> MyCustomProductCreateAction(){
...
}
4 days ago
Thanks for your quick response.

I've to extend the native controller, view and model  in my plugin in order to add a new property and manage its value. I've already done it for customers, but on that case the native route is static so I was able to override it easly with a custom RouteProvider class.

I'll try to use the method attribute then and let you know about it.

Thanks a lot.
4 days ago
Hi @AdamK, "HttpPost" attribute didn't work but "Route" attribute worked like a charm.
Thanks.
4 days ago
Be careful that you don't override the "GET" action when you only mean to override the "POST"
4 days ago
silviobernardo wrote:

I've to extend the native controller, view and model  in my plugin in order to add a new property and manage its value.


There is another way to achieve this without overriding. An example of adding a property to the core entity is in Avalara tax plugin.
4 days ago
Hello,

Could you provide me more details about it, please? Like, which files should I analyse, what is that property name... there are lots of files and I'm a quite new in the nopCommerce world.

My goal is add a new property to Products in Admin area and manage its value.

Thanks.
4 days ago
Check out usage of IGenericAttributeService in the Avalara plugin, it's a way to save data by key to any BaseEntity.
4 days ago
Oh, yes I've already added generic attributtes successfully for customer by code. But in this case I have to add this in the Product table as client requirement.

Thanks for your support.