user1299582
user1299582

Reputation: 91

How to add new tables to NOPCommerce v2.4

I am new to NopCommerce v2.4 and wondering where do I write my code (by creating new model in admin or nop.web section)

Upvotes: 9

Views: 5907

Answers (5)

LateshtClick.com
LateshtClick.com

Reputation: 616

One Step is remaining Behnam Esmaili's answer

Create table in NopCommerce database.

Note: Manually create table in database is necessary.

Finally create controller and its View.

If you want to get to more detail, Click here!

Upvotes: 0

Behnam Esmaili
Behnam Esmaili

Reputation: 5967

I spent plenty of time for delving into this problem' depths. I can summarize the solution as follows:

  1. Create The Entity Class (e.g Entity.cs)

    Path : Nop/Core/Domain/Entity.cs

  2. Create The Mapping Class (e.g EntityMap.cs)

    Path : Nop/Data/Mapping/EntityMap.cs

  3. Create a Model for MVC (e.g EntityModel.cs)

    Path : Nop/Admin/Models/EntityModel.cs OR Nop/Web/Models/EntityModel.cs

  4. Create a validator for model (e.g EntityValidator.cs)

    Path : Nop/Admin/Validators/EntityValidator.cs OR Nop/Web/Validators/EntityValidator.cs

  5. Create A Mapping Configuration On AutoMapperStartupTask.cs for Entity and Model

    Path : Nop/Admin/Infrastructure OR Nop/Web/Infrastructure

  6. Apply Mapping between Model and Entity on MappingExtensions.cs

    Path : Nop/Admin OR Nop/Web

  7. Create a service class and service interface (e.g EntityService.cs , IEntityService.cs)

    Path : Nop/Services/EntityService.cs AND Nop/Services/IEntityService.cs

  8. Register service for dependency injection

    Path : Nop/Web/Framework/DependencyRegistrar.cs

  9. Finally Create Controller and View for given model

as Nop Commerce uses the very first release of MVC3, database migration is not supported and you must make changes to database tables by hand. Because MVC code-first must drop and recreate your database for reflecting changes to your database.

If you want to get to more detail in any step, let me know - I can describe each step in detail. Hope this helps.

Upvotes: 20

snowp
snowp

Reputation: 491

Behnam Esmaili Solution is correct but they forgot to add one Step to Register Newly Created Controller Service in Presentation ==> Nop.Web.Framework ==> DependencyRegistrar.cs like this

builder.RegisterType<EntityService>().As<IEntityService>().InstancePerHttpRequest();         

Upvotes: 3

Mohamed Arabi
Mohamed Arabi

Reputation: 107

@Behnam Esmaili

Answered the perfect answer, But you should face a problem with creating the controller because you wan't be able to create an instance from the IEntityService because nopCommerce using Dependency Injection and this is being controlled by AutoFac container.

So you shold Check this post on nopCommerce forum, That will be useful to help you complete the work.

There is an other note, If you want to avoid do the database changes by hand you should do the steps from 1 to 8 on a fresh version of nopCommerce and install it the database will be created with the changes you made to the models.

Upvotes: 1

Kiru
Kiru

Reputation: 3565

This question been replied in NOPCommerce forum here

http://www.nopcommerce.com/docs/75/plugin-with-data-access.aspx

Upvotes: 2

Related Questions