Accessing Database?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
What is the proper way to access the database in MVC 2.4?

What I'm needing to do is to write some data to the Orders table of the database with some custom information I get back from our backend system.
12 years ago
The cleanest way would be use the webservices if you need to connect right away or create a class that implements ITask if you want to batch process some files on a recurring basis.  

I have a task that checks an import directory for a XLS that is Customer data from our ERP.  It just uses the ICustomerService to save the new data.
12 years ago
AndyMcKenna wrote:
The cleanest way would be use the webservices if you need to connect right away or create a class that implements ITask if you want to batch process some files on a recurring basis.  

I have a task that checks an import directory for a XLS that is Customer data from our ERP.  It just uses the ICustomerService to save the new data.


Which web service inside of nop would give me access to write data to the orders table?

I would like this to be done via realtime and not batch process.
12 years ago
I've never used it but it's the Nop.Plugin.Misc.WebServices plugin.
12 years ago
AndyMcKenna wrote:
I've never used it but it's the Nop.Plugin.Misc.WebServices plugin.


Couldn't i just use the Nop.Services.Orders library to update the order?
12 years ago
You can but you then need to make sure you also use the DI stuff because it's a long chain of dependency.

https://www.nopcommerce.com/boards/t/14723/create-new-instance-of-_orderservice.aspx?p=2

I tried going down that road of manually creating all of the services and repos that I would need.  This first post on page 2 explains the better way to do it.
12 years ago
vitran23 wrote:
I've never used it but it's the Nop.Plugin.Misc.WebServices plugin.

Couldn't i just use the Nop.Services.Orders library to update the order?


Looks like I found another way during the ProcessPayment() by using the result to write to the database.

If I add a few columns to the "order" table what would I need to change in the program in order for it to be able to write to those fields?
12 years ago
https://www.nopcommerce.com/docs/73/updating-an-existing-entity-how-to-add-a-new-property.aspx

Probably just the Core, Data, and Service
12 years ago
AndyMcKenna wrote:

Thanks for the link.
12 years ago
What I have done successfully in the past is the following, with the basic concepts in mind.
1. You should not directly manipulate the Nop base code because you screw yourself in terms of the upgrade path.
2. Create a new project I.E. YourCompany.Commerce.Service just like Nop.Services.
3. Create a new project I.E. YourCompany.Commerce.Core
4. In YourCompany.Commerce.Core, create the new entity you need and inherit from BaseEntity
5. Create a new schema in your NopCommerce DB I.E. Extended
6. Create a domain object in your YourCompany.Core.Domains namespace (basically copy the architecture in any of the Nop.Core.Domains objects.
7 Create a YourCompany.Commerce.Data project to create that mapping to your custom extended.Table entity (again copy the architecture)
8. In yourCompany.Services create a service that implements the Nop.Services service you want to extend, most of the methods are virtual so you can override the specific method you need to control.
Now in order to get the DI to work,  you need to create a DependencyRegistrar class just like the Nop ones, but set the priority higher say to 1.
9. Reference your custom service lib from the NopCommerce.Presentation/web project. It will get injected into the application and will be called instead of the service specified by default Nop.Services with a priority of 0.
10. Your service will essentially replace the Nop.Service class you inherited from, making calls to your custom domain object as needed, and when Nop is upgraded, you spend about an hour fixing the compilation errors that break your custom implementation and you are back on your way.
I implemented a custom Nop.Services.Customer.CustomerRegistration service this way that authenticates users against a standard aspnet_membership provider in another domain, on login if the customer does not exist, I use a view in a sperate namespace to do the resolution and auto create a customer based on that data, all works seamlessly. It sounds like a lot of work but I was done with it in a day, and besides creating your own structure that mimics the Nop libraries allows you to extend the application further down the line as you see fit.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.