How to extend a model view in nopcommerce?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
What is the best solution to extend Nop.Web.Models classes to be able to use them inside the custom plugins by keeping in mind the future updates?

For example I need to add custom fields in Nop.Web.Models.Customer.CustomerInfoModel as well as have access to all the attributes of CustomerInfoModel  inside the custom view.
9 years ago
arlen wrote:
What is the best solution to extend Nop.Web.Models classes to be able to use them inside the custom plugins by keeping in mind the future updates?

For example I need to add custom fields in Nop.Web.Models.Customer.CustomerInfoModel as well as have access to all the attributes of CustomerInfoModel  inside the custom view.


Hi arlen,

I wouldn't touch the Models but extend them using the CustomProperties dictionary of the BaseNopModel.
Each Model in nopCommerce inherits from the BaseNopModel, so you can take advantage of CustomProperties dictionary and add your custom fields there.

Hope this helps!
7 years ago
Do you know how to use value from CustomProperties in partial view pages in nopCommerce?
7 years ago
atulrungta wrote:
Do you know how to use value from CustomProperties in partial view pages in nopCommerce?

In the BaseNopModel class it's implemented as a dictionary of string keys and object values (Dictionary<string, object>) so you have all the methods and properties of a Dictionary at your disposal. An example of retrieving a value by key and casting it to a string:

var MyValue = (string)Model.CustomProperties["MyKey"]
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.