Model Override - Plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 Jahre weitere
Hi there!

Im creating a new theme and overriding the ProductOverviewModel, like this:


namespace Nop.Plugin.ThemeHelper.AC.Models
{
    public partial class ACProductOverviewModel : ProductOverviewModel
    {
     ....
    }
}


This is working good, but there is a lot of work after, on replacing all views using the ProductOverviewModel to my new ACProductOverviewModel, so new properties can be displayed.

My question is: Is there a simple way to override web models, without touch the nop source?

NOP 3.7

thanks!
8 Jahre weitere
iob2000 wrote:
Hi there!

Im creating a new theme and overriding the ProductOverviewModel, like this:


namespace Nop.Plugin.ThemeHelper.AC.Models
{
    public partial class ACProductOverviewModel : ProductOverviewModel
    {
     ....
    }
}


This is working good, but there is a lot of work after, on replacing all views using the ProductOverviewModel to my new ACProductOverviewModel, so new properties can be displayed.

My question is: Is there a simple way to override web models, without touch the nop source?

NOP 3.7

thanks!


You can do like bellow
namespace Nop.Plugin.ThemeHelper.AC.Models
{
    public partial class ACProductOverviewModel
    {
public ACProductOverviewModel()
{
  ProductOverviewModel= new ProductOverviewModel();
}
     public ProductOverviewModel ProductOverviewModel{get;set;}
........
    }
}


This process minimized your coding
8 Jahre weitere
So, it will be like this?


namespace Nop.Plugin.ThemeHelper.AC.Models
{
    public partial class ACProductOverviewModel
    {
       public ACProductOverviewModel()
       {
           ProductOverviewModel= new ProductOverviewModel();
       }
      
       public ProductOverviewModel ProductOverviewModel{get;set;}

       public string newProperty1 {get;set;}
       public string newProperty2 {get;set;}
    }
}
8 Jahre weitere
iob2000 wrote:
So, it will be like this?


namespace Nop.Plugin.ThemeHelper.AC.Models
{
    public partial class ACProductOverviewModel
    {
       public ACProductOverviewModel()
       {
           ProductOverviewModel= new ProductOverviewModel();
       }
      
       public ProductOverviewModel ProductOverviewModel{get;set;}

       public string newProperty1 {get;set;}
       public string newProperty2 {get;set;}
    }
}


Yes.
7 Jahre weitere
Hi everybody.

How to extend the model Without having to change the name of it, for example:
public partial MyModel
{
  public string field1{get;set}
  public string field2{get;set}
}

Now i want to create another model that contain MyModel,Without having to change the name of it.

public partial MyModel: MyModel
{
  public string field3{get;set}
  public string field4{get;set}
  public string field5{get;set}
  public string field6{get;set}
}

Thanks a lot.
7 Jahre weitere
Hamidnch wrote:
Hi everybody.

How to extend the model Without having to change the name of it, for example:
public partial MyModel
{
  public string field1{get;set}
  public string field2{get;set}
}

Now i want to create another model that contain MyModel,Without having to change the name of it.

public partial MyModel: MyModel
{
  public string field3{get;set}
  public string field4{get;set}
  public string field5{get;set}
  public string field6{get;set}
}

Thanks a lot.


try like bellow==>



public partial MyModel
{
  public string field1{get;set}
  public string field2{get;set}
}


public partial MyModel
{
  public string field3{get;set}
  public string field4{get;set}
  public string field5{get;set}
  public string field6{get;set}
}

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.