WebSphere Commerce Enterprise

Creating the price rule element task command

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

  1. Open WebSphere Commerce Developer and switch to the Enterprise Explorer view.
  2. Create a package for your task command files:
    1. Navigate to WebSphereCommerceServerExtensionsLogic > src.
    2. Right-click the src folder; then click New> Package.
    3. In the Name field, type:

      com.your_company_name.price.rule.commands.element

      Make sure this package name matches what you specified in the runtime XML when you created the price rule element template definition: see the name parameter for the <class> element.

    4. Click Finish.
  3. In the new package, create a new interface class for your price rule element task command that extends from the PriceRuleElementCmd interface.

    Make sure this class name matches what you specified in the runtime XML when you created the price rule element template definition: see the name parameter for the <class> element.

    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();
    }
  4. 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.

  5. For any server-side error messages in the task command, create a new message key class:
    1. Navigate to WebSphereCommerceServerExtensionsLogic > src.
    2. Right-click the src folder; then click New> Package.
    3. In the Name field, type:

      com.your_company_name.price.rule.logging

    4. Click Finish.
    5. 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";
      
      }
    6. Save the class file.
  6. Create a properties file to define the server-side error message text:
    1. Navigate to WebSphereCommerceServerExtensionsLogic > src.
    2. Right-click the src folder; then click New> Package.
    3. In the Name field, type:

      com.your_company_name.price.rule.properties

    4. Click Finish.
    5. 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.
    6. Save the properties file.