Custom conditions
Custom conditions can be created and used to build a promotion. You can create your own custom promotion conditions to ensure that your available promotion types meet your business needs.
When you are creating a custom condition for a promotion
type, you must follow the expected XML format. This format is required
so that the promotion engine can use your condition when the engine
evaluates promotions on the storefront. The following code is a sample
custom condition that you can use to model your own custom conditions:
<CustomConditions>
<Condition impl= "com.myCompany.condition.custom.MyOtherMoreComplexCondition">
<!-- where myCompany is a custom package name -->
<ConfigParameter1>XXXX</ConfigParameter1>
<ConfigParameter2>
<CP2.1>YYYY</CP2.1>
<CP2.2>ZZZZ</CP2.2>
</ConfigParameter2>
</Condition>
</CustomConditions>
A custom condition must implement
the com.ibm.commerce.marketing.promotion.condition.Condition interface,
which is a subclass of XMLizable. The following code is an example
definition of this interface:
package com.ibm.commerce.marketing.promotion.condition;
import com.ibm.commerce.marketing.promotion.runtime.PromotionContext;
import com.ibm.commerce.marketing.promotion.xml.*;
public interface Condition extends XMLizable {
/**
* IBM copyright notice field.
*/
public static final String COPYRIGHT =
com.ibm.commerce.copyright.IBMCopyright.SHORT_COPYRIGHT;
boolean evaluate(PromotionContext context)
throws PromotionConditionEvaluationException;
}
The evaluate method is expected to return either true
or false. If true, the condition is considered satisfied. If false,
the condition is considered not satisfied and the promotion to which
this custom condition belongs will not be applied.Note: All custom
conditions must be thread safe and re-entrant.