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)

PabloC
  • 404
  • 2
  • 13
user1299582
  • 91
  • 1
  • 3

5 Answers5

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.

Behnam Esmaili
  • 5,835
  • 6
  • 32
  • 63
  • 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. – arlen Sep 27 '12 at 18:44
  • 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? – arlen Sep 27 '12 at 18:50
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();         
snowp
  • 495
  • 1
  • 6
  • 22
2

This question been replied in NOPCommerce forum here

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

Kiru
  • 3,489
  • 1
  • 25
  • 46
  • 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. – user1299582 Apr 02 '12 at 18:33
  • 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 folder – Kiru Apr 03 '12 at 08:27
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.

Mohamed Arabi
  • 97
  • 1
  • 10
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!