Custom Extension

RazorCart provides the ability to create custom extensions/plugins which executed within the workflow methods when needed, an extension is basically a method that triggered during the Pipeline Actions and it can be called before the action, after or even on both events, in this article you will learn how to build your own custom extension using your c# code in Visual Studio.

 

Requirements:

  • Microsoft Visual Studio 2012 or newer
  • C# development skills

Getting Started

1. The first step is to download the Visual Studio example project:

  Download the Extension Example Project

2.  Unzip the file you just downloaded and place it in the Library folder in your DNN root folder

 
3. Open the project in Visual Studio, you will see that the project contains a class MyService which inherited from RazorCart.Core.ActionPipeline.OnCheckoutComplete and implementing the interface RazorCart.Core.ActionPipeline.IRunAfterAction, that means this MyService method will be triggered just after the Action OnCheckoutComplete finished.
 
 
4. The two interfaces IRunAfterAction and IRunBeforeAction both require to have the configuration method of the extension settings implemented: public void Config(List<ExtensionSetting> settings), in this method we can add the extension admin settings page when activating the extension from Admin Console. The extension class properties are pretty similar to the PipelineAction properties:
  1. ActionID: an integer identity value for the action method, this value will be shown in the Event Viewer if your code throw an exception.
  2. ActionName: a string value to describe your action name, this will be also display in the Event Viewer if your code throw an exception.
  3. Execute: this is where you will have your code that to be executed, the parameter context will be passed from the Workflow Actions so you can get the values which were initialized/updated during the workflow.
5. Pipelines that can implement the Extension methods:
  1. CartPipeline: The cart operation workflow actions, get called when you add an item to the shopping cart.
  2. CalculatorPipeline: The cart totals calculation workflow actions, get called when calculating the cart totals.
  3. CheckoutPipeline: The checkout operation workflow actions, get called when the user proceed with the checkout.
6. ExtensionSetting class:
  1. SettingType: used to determine the setting field type, value can be (Label, TextBox, DropdownList, RadioButtons, CheckBox, MultiLineTextBox, Information, Error, Warning, Hidden, Html)
  2. SettingLabel: the setting label/title that will be displayed in the front-end.
  3. SettingName: the setting key/name value as it will be saved, this name shall be used to get the setting value for.
  4. SettingOptions: a Dictionary<string, string> type, applies only to certain setting types (DropdownList, RadioButtons).
  5. SettingValue: the default/initials setting value, when using the types (Information, Error, Warning, Label or Html) this well be permanent as the user cannot change the value.
  6. Required: a Boolean (true/false) type that will set the required HTML field attribute if set to true.

 

The Example

We have included an example with the above project that adds a radio button options and credentials textboxes, those credentials will be used in the example extension to calls a web service:
 

Building & Deploying

After you build your extension assembly and deploy it to your DNN\bin folder, you will need to activate it from the Store setup, go to the RazorCart Admin-Console > Store Setup > Extensions, check the activate box next to the namespace you have chosen ("Extension.Example.MyService" if you haven't change it) and click save, a configuration icon will appear to setup the extension.
 
 
To access the Extensibility Setup page click on the Admin Menu in your DNN portal, then select RazorCart Admin Console:
 
DNN ≤ 8
 
DNN 9
 
 
From the left-side menu go to Store Setup > Extensions
 
 
Activate the Extension and click on the gear icon, this will open a extension settings page that we implemented in the config method, the admin can now save the settings values, and when executing the extension all these values can be retrieved by accessing "context.ExtensionConfig".
 
 

 
 
Now you have successfully build a RazorCart Extension.Plugin! If you have any questions, please Contact Us.

Add Feedback