Best way of extending nop web api plugin?

2 个月 前
Hello everyone, I have a product that I want to improve, and I already have an official NOP web API plugin. My goal is to add the ability to search for products by SKU and add multiple products at once using new methods. I want to achieve this without modifying any NOP core codes, even if it's the NOP official plugin. Therefore, I added a new plugin to extend the capabilities of the current API plugin.

The official plugin already has a method for adding products to the cart using product ID, called "AddProductToCartFromDetails". It looks like this:

AddProductToCartFromDetails([FromBody] IDictionary<string, string> dictionary, int productId, [FromQuery, Required] ShoppingCartType shoppingCartType)

To achieve my goal, I wrote a new method called "AddProductToCartFromDetailsBySku". It looks like this:

AddProductToCartFromDetailsBySku([FromBody] IDictionary<string, string> dictionary, string sku, [FromQuery, Required] ShoppingCartType shoppingCartType)

I believe that it would be more secure to find products by SKU and then call the official API plugin methods. Do you agree? If so, what would be the best way to do this? Should I use HttpClient calling or reflection, or is there another suggestion you would make?
2 个月 前
Hi. The easiest way is to extend an existing plugin right inside it, we were counting on such changes, that’s why almost all classes are partial and methods are virtual so that it would be easier to make changes and not be afraid to update the plugin to a new version.
1 个月 前
Hello Sergei, thanks for your response.

I have decided to write a new plugin and override the routes of the methods that I want to modify. Additionally, I have overridden and inherited some of the additional methods and classes, among other things.

It was a bit challenging to do due to the complexity of the application. When developing my nop solution, I never touched the core codes such as nop.core, nop.services, nop.web, and nop.framework. Furthermore, I never touched the official API plugin to avoid any issues with updating the core nop or API plugin.

But, I am not sure if it's really worth it.
1 个月 前
Hi. There is only one point that needs to be taken into account. If you are making custom changes for yourself or a single case, then it is better and easier to do everything directly in the kernel, the main thing is to work in separate files, and then there will be no problems with the update. But if you are making changes for multiple sites, then it is better to use standalone plugins

mtas wrote:
Hello Sergei, thanks for your response.

I have decided to write a new plugin and override the routes of the methods that I want to modify. Additionally, I have overridden and inherited some of the additional methods and classes, among other things.

It was a bit challenging to do due to the complexity of the application. When developing my nop solution, I never touched the core codes such as nop.core, nop.services, nop.web, and nop.framework. Furthermore, I never touched the official API plugin to avoid any issues with updating the core nop or API plugin.

But, I am not sure if it's really worth it.