Override Action Method Using Plugin into nopCommerce3.8
Take a look at this simple tutorial that demonstrates how to override the action method in nopCommerce 3.8.
Join the DZone community and get the full member experience.Join For Free
This article shows you how to override the action method in nopCommerce 3.8 version. In this article, I am going to override the Contact us form to extend its functionality. But this action method override way is not worked over seo URL (route value) like product URL, category URL, etc.
Override Contact Us page
Now, I am going to show how to override the Contact us page using plugin. This Contact us form has fields like
content, but I want to add one more field,
contact no, that will help me to get the contact details of the person who is going to post this form.
You may also enjoy: A Beginner's Guide to Overriding Methods
For this feature, I am going to add one project into the plugin folder and add the ContactusController.cs, RouteProvider.cs, ContactUsModel.cs, ContactUs.cshtml, app.config, description.txt, OverrideActionMethodProvider.cs, packages.config, and web.config. For now, I refer to the
My plugin structure is as below:
I have created:
- ContactSscontroller.cs => for the Contact us form
- RouteProvider.cs => is used to override the route URL of Contact us. If the user calls the Contact us URL, then our plugin form will be displayed instead of default nopCommerce form (action method).
- ContactUsmodel.cs => to add one more property of
- ContactUs.cshtml => This view file displays content of Contact us form.
- OverrideActionMethodProvider.cs => creating a method for the
uninstallprocess for plugin
ContactUsmodel.cs model file. I have added my new property into this model. I have used the existing
ContactUsModel of nopCommerce.
routeProvider file overrides the existing route value:
I have removed the existing route value of Contact us and added my Contact us route value. I have mentioned my controller name, action method name, and namespace for this.
Contactus.cshtml view file:
I have only added phone no text into this view file and changed the form post action method name to post into my controller.
This controller helps me to display my Contact us form and get the form detail into my end to get new property value.
I hope you've now understood how to override the action method using plugin in nopcommerce3.8. I have attached the source code of this plugin so you will be able to get a better idea about this.
Published at DZone with permission of sangeet shah. See the original article here.
Opinions expressed by DZone contributors are their own.