Create a new task command interface and its associated
implementation class for your new price rule element. The task command
performs the work for the price rule element and validates parameters.
Before you begin
Review the following topics to ensure that you understand
task commands for price rule elements, as well as the relevant class
and interface:
- Price rule element task commands
- com.ibm.commerce.price.rule.commands.element.PriceRuleElementCmdImpl class
- com.ibm.commerce.price.rule.commands.element.PriceRuleElementCmd interface
About this task
The price rule element task command must be a class that
implements the PriceRuleElementCmd interface and should extend from
the PriceRuleElementCmdImpl class.
Procedure
- Open
WebSphere Commerce Developer and switch to the Enterprise Explorer
view.
- Create a package for your task command files:
- Navigate to WebSphereCommerceServerExtensionsLogic
> src.
- Right-click the src folder; then
click New > Package.
- In the Name field, type:
- Click Finish.
- In the new package, create a new interface class for your
price rule element task command that extends from the PriceRuleElementCmd
interface.
Here
is an example of a task command for a condition that determines whether
the customer registered on, before, or after a specific date, and
is therefore entitled to special prices:
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();
}
- In the new package, create a task command implementation
that extends from the PriceRuleElementCmdImpl class. This task command
must implement the interface that you defined in the previous step.
Give the class a name that uses this syntax: pricerule_element_nameElementCmdImpl;
for example,
RegistrationTimeConditionElementCmdImpl
.
For conditions and actions, this task command implementation
must implement the method performExecute. The task
command implementation can also implement the method validateParameters to
validate that the element has all the required user interface parameters.
- For any server-side error messages in the task command,
create a new message key class:
- Navigate to WebSphereCommerceServerExtensionsLogic
> src.
- Right-click the src folder; then
click New > Package.
- In the Name field, type:
com.your_company_name.price.rule.logging
- Click Finish.
- In the new package, create a new class file to contain
the message keys, for example, CustomPriceRuleMessageKeys.java.
The following is an example of this type of class:
package com.mycompany.commerce.price.rule.logging;
public class CustomPriceRuleMessageKeys {
public final static String _ERR_NEW_REGISTERED_TIME_IS_MISSING = "_ERR_NEW_REGISTERED_TIME_IS_MISSING";
}
- Save the class file.
- Create a properties file to define the server-side
error message text:
- Navigate to WebSphereCommerceServerExtensionsLogic
> src.
- Right-click the src folder; then
click New > Package.
- In the Name field, type:
com.your_company_name.price.rule.properties
- Click Finish.
- In the new package, create a properties file to define
the message text.
Use a name similar to the following: WcPriceMessages.properties
The
following is an example properties file:
_ERR_NEW_REGISTERED_TIME_IS_MISSING=Specify a date and time in the Date and time field.
- Save the properties file.