How to add new tables to NOPCommerce v2.4
Asked Answered
P

5

9

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)

Plautus answered 29/3, 2012 at 1:16 Comment(0)
A
20

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.

Andryc answered 2/6, 2012 at 18:0 Comment(2)
Could you please explain in detail or any example? I create a table in database but I don't want to create a new plugin, I just want to add the classes in Nop.Core Nop.Data Nop.Services and ... but i don't know about the process. I just want to create the service and call the service to load my dropdown lists in Nop.Web or Nop.plugin.Aphonia
Should I create a new plugin for new entity in my database and reference it in other projects like other plugins or Nop.Web or Admin projects instead of adding my classes in Nop.Core Nop.Data Nop.Services?Aphonia
I
3

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();         
Intermittent answered 19/11, 2012 at 11:50 Comment(0)
A
2

This question been replied in NOPCommerce forum here

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

Aesop answered 29/3, 2012 at 20:23 Comment(2)
I still need some more help. I added that project in my Plugins I am not able to see this plugin in admin -> Configuration -> plugins I added following line in \Presentation\Nop.Web\Views\Catalog\ProductTemplate.SingleVariant.cshtml @Html.Action("Index", "Tracking", new { productId = Model.Id }) I am getting this exception: Execution of the child request failed. Please examine the InnerException for more information. InnerException: {"The controller for path '/p/5/1-oz-krugerrand' was not found or does not implement IController."} I just added few products through admin.Plautus
I havent worked on plugins, but remember added some existing plugins. I would like you to verify if you have the build output path set to Nop.Web\Plugins\ and also check the InstalledPlugins.txt in App_data folderAesop
P
1

@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.

Pheni answered 10/10, 2012 at 23:49 Comment(0)
L
0

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!

Lisle answered 4/9, 2016 at 11:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.