Best way to approach new project using Orchard

Topics: General
Jun 14, 2012 at 1:01 PM

Hi,

I have a new project that I want to use orchard for but am unsure how to approach it and was hoping for some advice.

Bascially it will be a B2B site that integrates into our back end system (Dynamics NAV).
I cannot decide if it is better to create content types for the products and have them all stored in the Orchard DB or use web services to query NAV at the time and not store them in Orchard.

Pros for use orchard is it would be quicker? Would make best use of Orchard (ie using content types etc), my problem with this is the available stock figure wouldn't be upto date (orders would be processed on the site and directly on NAV). So if I have a stock figure within orchard it wouldn't take into account any orders placed directly onto NAV.

If I go down the other route of using web services I don't think it would be as quick (although the web services querys are quick) - plus I would lose things like easy searching and paging etc I would have thought...

There would be other information like past orders, invoices/credits (pdfs) etc.

hmmm... think I may have answered my own question, but would be interested in anyones thoughts and if anyone has done anything like this before.

I have only just started with Orchard but can see the potential... just need to experiment more I think.

Thanks

Roland

 

Coordinator
Jun 15, 2012 at 5:30 AM

Synchronizing two data sources is no fun. I'd go the web service route.

Jun 18, 2012 at 11:52 AM

How would you suggest to go about this then, I take it I wouldn't be able to use things like the search functons and built in paging etc - makes me wonder if for this project Orchard might not be the best route to go down?

I came across this article thats shows how to connect to other data, though its just a normal MVC controller as a module http://www.kresner.com/jonathons-orchard-cms-blog/creating-a-custom-orchard-cms-module-that-reads-data-from-the-central-climbfind.com-database

Just a bit puzzled as to how best approach it.

Developer
Jun 18, 2012 at 12:51 PM
Edited Jun 18, 2012 at 12:54 PM

Actually, if the web service data needs to be displayed on a website that is to be managed by some user, Orchard would still make sense because it doens't really matter wether the content comes from the Orchard database in the form of content items or if it came from a web service. Because at some point, these items will be transformed into shapes, which are the actuall things that will be rendered.

For example, your controller would retrieve information from your web service and create shapes. These shapes can be rendered using Razor templates. The Pager is also a shape, which you would also create from your controller. You could checkout the core Contents module to see how to use the pager shape.

As for using built-in search functions, I think you could index the retrieved information like any other piece of content by implementing a ContentHandler. Although I don't know the exact specifics, you could create for example a "WebServiceDataPart" part that knows how to retrieve information from the web service.
Now that you have this content part, you could then implement the OnIndexing method on your custom ContentHandler. Inside that method you would add data to the index. Have a look at how this is done in the BodyPartHandler in Orchard.Core.

 

Jun 19, 2012 at 12:37 PM

Thanks - sounds good and a definate starting point.

On a side note, any idea when your Orchard WebModule project will be updated (sorry sure you keep getting asked!)

Developer
Jun 19, 2012 at 8:38 PM

No problem, it's nice to know that people are looking forward to it. The way things currently look, I might be able to have it updated before the end of this month.

Aug 8, 2012 at 1:39 PM

Okay so taking this further then...

I create a WebServcieDataPart - but how would it know what to return - would I inside a constructor connect to the webservice and populate the properties of the datapart... but unless I pass an id of somesort to the constructor it would return the entire block of data, not just 1 record if that makes sense. Then how would it work in a query... somewhat puzzled at the moment.

Aug 8, 2012 at 4:38 PM

Right been looking into this, from the looks of it in the handler of the part I need to do something in there, i have found this

http://stackoverflow.com/questions/4727843/how-to-change-orchard-record-repository/5086069#5086069

But I'm struggling to figure out where to go now.

In the constructor I wouldn't put the usual Filter.Add(StorageFilter.Add(repository) as it does have one, I already have a class that inherits IDependency and this class can access my web service - I just can't work out how to use it in the handler.

Developer
Aug 8, 2012 at 5:49 PM

You shouldn't do anything in the contructor of your part; instead, use the part's Driver to connect to the webservice. For example, in the Display method's shape factory method, connect to the web service and store its data onto the shape you're building. As to where to get what ID from, that depends on where to get what ID from :)

Or if you're not trying to display data, but instead import data, you don;t need a content part at all: just inject an IRepository<MyEntity> into your controller, and in one of your actions connect to the web service, read the data, and insert it into your repository.

Aug 9, 2012 at 10:48 AM

Thanks - but think I need to explain myself better.

I have a part with the properties, no record for it as I don't store anything in orchard.

I've got a widget to connect to the web service and display the data with pagers etc, can do the same thing with controllers to... but I want to use query, so I created a Type that contained my part, setup my query to my type etc, but as you would expect when you run the query it returns nothing - which it wouldn't as the data isnt in Orchard - from what I read yesterday and understood (which could be wrong!) i need a handler for my part that will get the data - I can use it in the driver for this can I?

I already have a driver for the part which is being used in the widget...

I might be way off base here, but hopefully that explains the scenario better

Cheers

Developer
Aug 9, 2012 at 6:27 PM

I'm confused. You're saying that you want to fetch data via a web service, but that you want to use query: what type of query you're referring to? Do you mean the call to the web service?

From what I understood, you simply want to fetch data from a web service and display that data as part of the widget. If this is correct, then you should query the web service from within the shape factory method in your driver (and you probably want to cache the results using ICache)

If I misunderstood, let me know.

Aug 9, 2012 at 9:32 PM

Sorry probably not explaining it well.

I created a service and am able to show the data in a widget (like you said above) - that works fine. But then I thought it might be better to use Projections for certain things, so I would need to create a query based on the Content Type that is made from the part, but as Orchard doesnt store the data the query wouldn't return anything. So I need a way of getting the record for my content type where the part data is in an external data source. I can get to the data via a web service - just don't know how to do it, or find examples of it. 

Does that make sense?

Aug 14, 2012 at 5:40 PM

Any ideas?

Developer
Aug 15, 2012 at 9:49 PM
Edited Aug 15, 2012 at 9:49 PM

I don't think I understand what you mean with part data being an external data source. In any case, if you're looking to use projections, have a look at existing IFilterProvider implementations: all you really have to do is return an IHqlQuery. If you could implement a custom IHqlQuery class that talks to your webservice, you should be good to go.

Another approach might be to first convert your data coming from the web service into content items. However, you would have now have 2 datasources, and synchronizing between them is no fun as mentioned.


Aug 17, 2012 at 4:23 PM

Thanks will take a look at the IHqlQuery stuff.

I think I may end up going down the route of having 2 datasources anyway, I won't be letting anyone change the content item from orchard anyway - the only thing i will have to do then is when the items are render maybe use jquery to get the current stock availability from the webservice. And as items won't be modified in orchard syncing is made a little earlier - so if I can figure out why tasks wont work (another thread I have started) I should be there.....

Thanks