Import Scheduler in Nopcommerce

Who can use an Import scheduler in nopcommerce:

Let us take the example of a logistics person who is watchful of the time always. This person will be working in a place suce as a warehouse and will be wanting timely movements. This is the kind of profile who would like to use the scheduler.

Nop Commerce Scheduler:

Nop comes with several types of schedulers but unfortunately there are no import schedulers available. We have therefore created a scheduler that scans products periodically. The scheduler has been built so as to apply business logic as well. For example for the Import products if a condition reached for certain products. For this we have to define a record in the ScheduleTask table in the import scheduler in nopcommerce. You need to know how to create a nopcommerce plugin to be able to make an import scheduler in nopcommerce.

Logic for creating an import scheduler:

We created a directory in the drive (D:Projects/Import/Product). In this path we pasted one excel file namely "Product_Update20130925130835". Excel file format looks like:

Header value will equal to column name in Product Table.
Now when the import scheduler in nopcommerce will call it will check is any file exist in folder "D:Projects/Import/Product " if yes then we will create loop on this file.

Nop Commerce: How to write a custom task plugin ?

I really like the nopCommerce framework more and more ! It has the ability to host some custom scheduled task, which is exactly what I need ! To complete this task I suggest to create a new plugin (you can follow this tutorial with a IMiscPlugin interface) then there are two major steps, and an option third:

1. Create your task

This is done by implementing the  ITask interface and it’s really simple because it only has one method to implement! 
Don’t forget to use constructor parameters to inject the service required by your  task. In my sample, I just demonstrate the injection of the ILoggerService:

2. Schedule your task

To schedule a task in the import scheduler in nopcommerce, you have to insert a row in the ScheduleTask table. To do this, I choose to use the ScheduleService with the InsertTask method, and call it in the Install method of the plugin. Of course I use the Uninstall method to remove my task.

3. Settings and configuration

As for any nopCommerce plugin, you can define a configuration view and store some settings for your task.
The configuration view must be declare in the GetConfigurationRoute of your plugin

Of course you have to create a controller named SampleTaskController in your controller directory, and return a view, and so one.

To store and use some custom settings, you have to create a class to represent your settings, and position the ISetting interface on it:

You also have to create them in the Install plugin method, and delete them in the Uninstall method :

Finally, in your task code, you can load the setting by injecting a ISettingService parameter in your constructor, and use the LoadSettings method this way:

Ok, so after installing your plugin, you will see your task in nopCommerce scheduled task administration panel !

Incase you need any kind of assistance with setting up of an import scheduler in nopcommerce, please contact us.

Subscribe to Newsletter
Community poll
Do you like nopCommerce?