Accessing Database?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Oh LOL if you want an easy way, you can create a plugin that exposes your service in terms of ODATA, check out google on MVC Odata, you basically just create controller methods in  your plugin that you can call via Rest post from wherever you are collecting the data, and just use the Nop services you need in your constructor for the backing service of your plugin, write the data, you are done. A plugin is clean because it can be installed, unistalled and is autonomous from the NOP application (lives in its own little world).
12 years ago
Well I've created my own payment plugin and I added a couple columns to the order table to store information that I receive back from my payment provider. So it sounds like it would be easier to stite to the DB within my plugin so what would I need to do to create the connection to be able to write to my extra columns?
12 years ago
Your plugin lives at a url like http://myhost/plugins/plugincontroller/ or something to that effect. My assumption is you are collecting the data from outside the Nop application domain and you want to save it in the Nop DB? If that is the case, in  your plugin, create a controller method that accepts a model or form post say
AcceptSpecificOrderInfo(NopOrderColumn1, NopOrderColumn2,MyCustomNopOrderColum3).
In the consuming application  you take the value from your provider, and do an System.Web.WebRequest.Post or something to that effect to http://myhost/plugins/plugincontroller/myspecificaction?nopcolum1=data2&nopcolum2=data2&mycustomnopcolumn=customdata3
The controller in the Nop domain will handle the request and do the save.
12 years ago
cmcginn wrote:
Your plugin lives at a url like http://myhost/plugins/plugincontroller/ or something to that effect. My assumption is you are collecting the data from outside the Nop application domain and you want to save it in the Nop DB? If that is the case, in  your plugin, create a controller method that accepts a model or form post say
AcceptSpecificOrderInfo(NopOrderColumn1, NopOrderColumn2,MyCustomNopOrderColum3).
In the consuming application  you take the value from your provider, and do an System.Web.WebRequest.Post or something to that effect to http://myhost/plugins/plugincontroller/myspecificaction?nopcolum1=data2&nopcolum2=data2&mycustomnopcolumn=customdata3
The controller in the Nop domain will handle the request and do the save.


Actually I'm getting information via a web service which returns back value a which I need to insert into 1 of the volume I created in the orders table.

I'm just curious how I can map the value I receive from my service call back to the column I created. Something simple as:
Column x = value from service.
12 years ago
Does the webservice hit a URL you specify? Like with paypal, you specify a return url and the service sends post variables back to the url you specify. In such a case you would simply specify the return URL (http://myhost/plugins/somecontroller/somereceiveraction) and then in your controller (receiver of the post data) you would simply do something like order.SomeValue = Request["VariableNameFromProvider"]. If you dont know the variables you can put a breakpoint in the receiver method and in the immediate window of VisualStudio do a Request.Keys.ToList() to see what they post back to you and map them to the Order object you are going to insert. If you want to get fancy you can create a CustomModel binder and on the bind method map the request and decorate your controller action with a [ModelBinder = MyModelBinder] and the request values would be mapped to your order entity the way you specify when it is called.
12 years ago
Additionally if you want to map the value back to the Order object, you would have to add the additional properties to the Nop.Core.Domain.Orders.Order object so it would get saved. On top of this you would have to open up the Nop.Data.Orders.OrderMap class and in the constructor you will see something like OrderMap()
{
this.Property(n=>n.Id)
this.Property(n=>n.OrderGuid)
}

you would have to add underneath this
this.Property(n=>n.MyCustomProperty)

MyCustomProperty should be a virtual property of the respective type in  your Nop.Core.Domain.Orders.Order class just like the Id, OrderGuid, etc... that come out of the box.

So you have your receiver that gets the data, then two other classes Nop.Core.Domain.Orders.Order, and Nop.Data.Orders.OrderMap to worry about.
12 years ago
cmcginn wrote:
Additionally if you want to map the value back to the Order object, you would have to add the additional properties to the Nop.Core.Domain.Orders.Order object so it would get saved. On top of this you would have to open up the Nop.Data.Orders.OrderMap class and in the constructor you will see something like OrderMap()
{
this.Property(n=>n.Id)
this.Property(n=>n.OrderGuid)
}

you would have to add underneath this
this.Property(n=>n.MyCustomProperty)

MyCustomProperty should be a virtual property of the respective type in  your Nop.Core.Domain.Orders.Order class just like the Id, OrderGuid, etc... that come out of the box.

So you have your receiver that gets the data, then two other classes Nop.Core.Domain.Orders.Order, and Nop.Data.Orders.OrderMap to worry about.


Thanks that's what I'm looking for but like you said when I upgrade I'll need to recreate this link.
12 years ago
Yep that goes back to my first response. First thing I do with a nop project is create the exact same structure MyCustom.Core, MyCustom.Services, MyCustom.Data include them in the nop project, and make all my changes there inheriting what I need from Nop. When its time to upgrade, I download the new Nop source, include my projects and fix what breaks (generally doesnt take more than a couple hours and I dont do trivial upgrades). That way I have complete control over the behavior but I dont like to modify the original code (open closed principle, open to inheritance closed to change) I dont change  tables, I add schema to the DB like extend... and any additional data I need I do as relatons with a foreign key from my table to the NOP table one way, Nop never knows about me I only know about it. So for example I would keep the base Order table and create an extended.OrderInfo table in my extended namespace, and in my MyCustom.Core.Domain, MyCustom.Data projects I create the DTO's that insert my data by overriding methods in the Nop classes within my MyCustom.... namespaces. Often to get the functionality I need I may only need to create a MyCustom.Services.OrderProcessingService class inheriting from Nop.Services.Orders.OrderProcessing and overriding say the place order method, call base.PlaceOrder, and finish with my custom stuff. You just have to be sure that in your projects you create an implementation of the DependencyRegistrar class and add your new services so they are picked up by the Nop DependencyReolver.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.