This component is not used where we need to access information from other sources like getting data from database or accessing other modules in commerce server using API.
We can pass key/Value pairs to the component using its interface. We can access these key/value pairs from 'config' parameter of MSCSExecute method.
Here are the few links from mdsn to configure and use scriptor component
http://msdn.microsoft.com/en-us/library/ms946865(CS.70).aspx
http://msdn.microsoft.com/en-us/library/ms944284(CS.70).aspx
Examples for using Scriptor component -
Applying value in 'DiscountPrice' property as product price if it is not null:
Requirement:
For every product there is a property called 'DiscountPrice'. If that property is not null then the value in that property should be considered as product price.
What to do:
Create a pipe line component which replaces the values for dictionary keys _cy_iadjust_regularprice, cy_placed_price if that is not null. To know more about the dictionary keys in order form got to http://msdn.microsoft.com/en-us/library/ms962766(CS.70).aspx.
Where to add the pipeline component:
In basket pipeline 'Query catalog info' queries the for catalog info from catalog module and creates the dictionary keys for all product properties like '_product_*' (* being name of the property). In 'Item price' stage after the 'requiredItemPriceCy' we have to add the scriptor component because in the 'requiredItemPriceCy' component values for the above said dictionary keys are calculated. we have to replace the calculated values.
(To know more about the commerce server pipeline components in all pipelines goto http://msdn.microsoft.com/en-us/library/ms916292(CS.70).aspx ).
How to add the pipeline component:
- Open basket pipeline of the application.
- Go to Item price stage and right-click on requiredItemPriceCy component and insert component -> after.
- Select stages as current stage and select commerce scriptor component and click ok.
- Go to component properties and scriptor tab.
- Check the internal radio and click on edit.
- It will open editor window where we need to copy the code in VB script.
- Copy the below code in the editor and click ok.
- Restart IIS.
There are three functions to implement using scriptor component
- MSCSExecute
- MSCSOpen
- MSCSClose
The only method that is compulsory and required is MSCSExecute. This method is used to implement the desired functionality. This method have four parameters namely
- config - Contains key/value pairs entered on the pipeline interface.
- orderform - Contains key/value pairs of orderform (or basket).
- context - Contains key/value pairs of context
- flags
How does Code Works:
orderform parameter is of type dictionary. Iterate through each Item and look for the key( key need not be present for every item as it depends on product definition). Read the value and if it is not null then change the values of the price keys to this value.
function MSCSExecute(config, orderform, context, flags)
Dim x
for each item in orderform.Value("Items")
for each key in item
if key="_product_DiscountPrice" then
x = item.Value("_product_DiscountPrice")
if IsNull(x) then
else
if IsNumeric(x) then
item.Value("_cy_iadjust_regularprice") = x
item.Value("cy_placed_price") = x
end if
end if
Exit for
end if
next
next
MSCSExecute = 1
end function
sub MSCSOpen(config)
end sub
sub MSCSClose()
end sub