nopCommerce 2.4 integrations

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Hi all,

I've been working on an integration project between nopCommerce 2.4 and an ERP system. So far we've defined communication information between them, and we are going to start development soon.

I'd like to know the best approach to create a windows services / console application that is going to consume nopCommerce services (orderservice, customerservice, etc).

Cheers.
11 years ago
Hi,

I had a problem to create a console application, the update method was not working at all, but the insert was working normally. So I made some changes to make it work.

File: Presentation\ISG.Web.Framework\DependencyRegistrar.cs
Method: public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)

   bool isConsoleApplication = false;

            if (ConfigurationManager.AppSettings["IsConsoleApplication"] != null)
                bool.TryParse(ConfigurationManager.AppSettings["IsConsoleApplication"], out isConsoleApplication);


            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider = (IEfDataProvider)efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                if (isConsoleApplication)
                    builder.Register<IDbContext>(c => new IsgObjectContext(dataProviderSettings.DataConnectionString)).SingleInstance();
                else
                    builder.Register<IDbContext>(c => new IsgObjectContext(dataProviderSettings.DataConnectionString)).InstancePerHttpRequest();

            }
            else
            {
                if (isConsoleApplication)
                    builder.Register<IDbContext>(c => new IsgObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).SingleInstance();
                else
                    builder.Register<IDbContext>(c => new IsgObjectContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerHttpRequest();

            }
11 years ago
I also had the same problem with ITask Services too - because the HttpContext.Current is null.

My work around to make it work in threads was to add this peace of code to initialize the HttpContext:

HttpContext.Current = new HttpContext(new HttpRequest(string.Empty, "http://localhost/", string.Empty), new HttpResponse(new System.IO.StringWriter(CultureInfo.InvariantCulture)));
            System.Web.SessionState.SessionStateUtility.AddHttpSessionStateToContext(HttpContext.Current, new HttpSessionStateContainer(string.Empty, new SessionStateItemCollection(), new HttpStaticObjectsCollection(), 20000, true, HttpCookieMode.UseCookies, SessionStateMode.Off, false));


and then resolve the Service Classes manually:

var userService = EngineContext.Current.Resolve<IUserService>();
            var customerService = EngineContext.Current.Resolve<ICustomerService>();

            var user = userService.GetAllUsers()[0];
            var owner = user.Customer;

            owner.Company = "Test Update " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
            customerService.UpdateCustomer(owner);

That is just a simple peace of code that I used to test the update process on the tasks. Hope it is clear enough!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.