Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
When creating a new promotion type, you need the following:
When creating a promotion, you first need a PromotionData. It should contain all properties needed to evaluate an order group and apply a reward. For example, it contains applicable entries and discount size. Add to PromotionData any property that should be edited by a marketer setting up promotions. Basic metadata properties, like name and valid dates, are provided from the base class.
PromotionData comes in three flavors, see below. When creating a promotion, you should inherit from one of these, never from PromotionData directly.
Once you have promotion data, you need to make a processor. The processor is responsible for evaluating if a promotion should apply a reward to an order group. You can implement the IPromotionProcessor interface directly, but the recommended way is to inherit from the abstract class PromotionProcessorBase<TPromotionData>. TPromotionData in this case should be the promotion data you created in the step above.
PromotionProcessorBase has one abstract method that needs to be implemented, Evaluate. The method is supplied with an IOrderGroup, which would be the cart, and a PromotionData and is responsible to evaluate if a reward should apply. The Evaluate method should return an IPromotionResult with information about if and how the promotion should be applied.
A promotion result should contain this:
The ApplyReward method should return a collection of PromotionInformation objects for each applied reward. A PromotionInformation has these properties:
For campaigns and promotions, you can add help texts in the form UI to guide users. To add help text for a custom group on the campaign or promotion form, add a Display attribute with GroupName property set to the name of a specific node within the “groups” section in the resource files.
Example:
[Display(GroupName = "MyNewGroup")]
public virtual decimal Money { get; set; }
The resource file will look like this:
<Commerce>
<…>
<groups>
<mynewgroup>
<help>This is help text for my new group</help>
</mynewgroup>
</groups>
<…>
</Commerce>
Your promotion may need a collection of currencies and amounts as part of your condition evaluation or reward logic. To achieve this, add an IList<Money> property to your custom promotion class. When used on a promotion type, such a Money collection is tightly coupled with the currencies available on the parent campaign.
Initially, any existing currencies related the promotion's campaign market added to the collection have the amount of zero. Changing the campaign market also changes available currencies in the property. Consider this when developing discount processors, because you must decide the desired behavior when one, or even all, amounts are set to zero.
Last updated: May 25, 2015