Access "PrepareCustomerInfoModel" method in CustomerController.cs from Plugin controller

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
Is there any solution to access "PrepareCustomerInfoModel" method in CustomerController.cs from Plugin controller?


protected virtual void PrepareCustomerInfoModel(CustomerInfoModel model, Customer customer, bool excludeProperties)
{
//
}
9 years ago
arlen wrote:
Is there any solution to access "PrepareCustomerInfoModel" method in CustomerController.cs from Plugin controller?


protected virtual void PrepareCustomerInfoModel(CustomerInfoModel model, Customer customer, bool excludeProperties)
{
//
}


You can create a new controller in your plugin that inherits from CustomerController, override the action result supplying a custom action name, and call your overridden implementation of PrepareCustomerInfoModel from that method.  


[ActionName("MyCustomAction")]
      new public ActionResult OverridenActionName(params) {
            ...
            this.PrepareCustomerInfoModel(args);
        }

...

protected override void PrepareCustomerInfoModel(params)
{
//if you need to alter code in the original method,
//you'll need to recreate it here, otherwise you can simply call the base method when needed
base.PrepareCustomerInfoModel(args);

}


and in your RouteProvider:

            routes.MapRoute("MyCustomRoute",
               "route/to/intercept",
               new { controller = "CustomCustomer", action = "MyCustomAction" },
               new[] { "my.namespace" }
            );


Hope that helps!
9 years ago
Thank you very much.

This link was helpful too.

http://tech.sunnyw.net/2013/11/nopcommerce-customization-with.html
9 years ago
arlen wrote:
Thank you very much.

This link was helpful too.

http://tech.sunnyw.net/2013/11/nopcommerce-customization-with.html


Nice article, although modifying the route in nop.web will cause problems when the plugin is uninstalled.
9 years ago
I agree. Touching Nop.Web is not a good approach specially if you are going to upgrade to a newer version.
9 years ago
AdamK wrote:
Thank you very much.

This link was helpful too.

http://tech.sunnyw.net/2013/11/nopcommerce-customization-with.html

Nice article, although modifying the route in nop.web will cause problems when the plugin is uninstalled.


It was built in a way that the controller was not as a plugin, but rather integrated with nop and still provide a future upgrade path. In the 2nd screenshot, the controller is inside a custom folder, not a plugin project.

At my early days, I didn't buy the plugin approach, I was more leaning towards MVC override approach and my team is quite happy with that.

This is what happen to the "upgrade" from 3.1 to 3.3. Personally the biggest pain was to upgrade our custom admin codes from telerik to Kendo UI, not anything else.

http://tech.sunnyw.net/2014/06/nopcommerce-painless-upgrade-from-31-to.html
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.