Price rule element task commands
Each condition and action has an associated task command called a price rule element task command. The task command performs the work associated with the price rule element. The price rule element template definition must specify which task command to use.
Task commands serve several functions, as described in the following table:
Task command function | Method called in the task command | Applies to conditions? | Applies to actions? |
---|---|---|---|
Validate the price rule element's parameters when the price rule is saved. | validateParameters |
Yes, if needed. | Yes, if needed. |
Perform the work for the element in the price rule. | performExecute |
Yes, mandatory. | Yes, mandatory. |
Format of a task command
A price rule element task command must be a class that implements the com.ibm.commerce.price.rule.commands.element.PriceRuleElementCmd interface.To understand the format of a task command, review the following code samples. The samples are for an example customized condition. The purpose of the condition is to determine whether the customer registered on, before, or after a specific date, and is therefore entitled to special prices.
This is an example of the task command interface class that extends from the PriceRuleElementCmd interface:
package com.mycompany.commerce.price.rule.commands.element;
import com.ibm.commerce.price.rule.commands.element.PriceRuleElementCmd;
public interface RegistrationTimeConditionElementCmd extends PriceRuleElementCmd {
public final static String defaultCommandClassName =
RegistrationTimeConditionElementCmdImpl.class.getName();
}
This is an example of a task command implementation that extends from the com.ibm.commerce.price.rule.commands.element.PriceRuleElementCmdImpl class. The snippets with numbers to the left are explained in more detail after the sample:
|
|
1 |
|
2 |
|
2a |
|
2b |
|
2c |
|
2d |
|
2e |
|
- 1 This snippet defines the
validateParameters
method to validate the condition parameters and return any errors. - 2 This snippet defines the
performExecute
method, which performs the evaluation work for the condition and returns true or false:- 2a This snippet gets the business context parameters for the customer.
- 2b This snippet gets the actual registration time of the customer.
- 2c This snippet calls the
getElementParameters
method to get the parameters that the task command uses to perform the evaluation. The parameters are defined as arguments in the price rule element task command. - 2d This snippet evaluates whether the condition should return true or false. For example, if the condition is customers who registered in February, then the condition should return true if the customer being evaluated registered in February.
- 2e This snippet informs the pricing services whether the condition returned true or false.
About the methods used in a price rule element task command
This table provides more details about the typical methods used in price rule element task commands for conditions and actions. For a full list and description of available methods for task commands, see the com.ibm.commerce.price.rule.commands.element.PriceRuleElementCmdImpl class.
Price rule element | Typical methods used |
---|---|
Condition |
|
Action |
|