Run a Scheduled Task against a specific store context

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
Our Nopcommerce site has two store configurations and each store has a different domain.

I need to implement a scheduled task for each store and this task calls a 3rd party API. The 3rd party API validates the caller URL, so I need each scheduled task to call the API using each Store's respective URL.

TaskA should call the API from siteA.com
TaskB should call the API from siteB.com


Has anybody done this for a multi store nopcommerce site?
Thanks
7 years ago
What we can do is use the task as a proxy, to call another Action.

So in your task:

1) Loop through all the stores
2) For each store, calls the specific URL, like "http://yourstore.com/mycontroller/myasction".
3) MyController.MyAction() in return will do the actual API calls.

I think this should work. :)
7 years ago
Thanks for your suggestion Woon, that did the trick!
5 years ago
Hello,

is there proper way to get store context on the scheduled task?

for now it seems not able to get proper store context id
even task ran like https://mystoreB.com/scheduletask/runtask

and we get the exception:

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: storeId
    at Nop.Services.Stores.StoreMappingService.InsertStoreMapping[T](T entity, Int32 storeId) in
   nopCommerce_4.10_Source\Libraries\Nop.Services\Stores\StoreMappingService.cs:line 131
   at Nop.Plugin.ProductFeeder.Services.UpdateStoreTask.Execute()

here is our code:

        public void Execute()
        {
            string progress = string.Empty;
            var storeScope = _storeContext.ActiveStoreScopeConfiguration;
5 years ago
just in case anyone will look for it - you have to use the following code:


var storeScope = _storeContext.CurrentStore.Id;
5 years ago
in your invoke method,
You need to first get all store from store entity (table)
then in for loop call your service with parameter -store id and store related endpoint.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.