Creating a task command for the customer segment attribute
Create a task command implementation class for your new customer segment
attribute and register the class in the CMDREG table. The task command validates whether a customer
belongs to a customer segment specified in a promotion or marketing
activity.
About this task
Procedure
- Open HCL Commerce Developer and switch to the Enterprise Explorer view.
-
Create a package for your task command files:
-
In the new package, create a task command implementation that extends from
CheckUserInMemberGroupCmdImpl class. Give the class a name.
For example,
ExtCheckUserInMemberGroupCmdImpl.The following example is a task command implementation for a new customer segment attribute. This attribute allows business users to specify that customers must have a certain number of loyalty points to be in the customer segment.
/** * This class extends the CheckUserInMemberGroupCmdImpl class to implement * the evaluation programming logic that handles the loyalty points * simple condition. */ package com.mycompany.membergroup.commands; import com.ibm.commerce.condition.ConditionUtil; import com.ibm.commerce.condition.SimpleCondition; import com.ibm.commerce.membergroup.commands.CheckUserInMemberGroupCmdImpl; import com.ibm.commerce.tools.segmentation.SegmentUtil; public class ExtCheckUserInMemberGroupCmdImpl extends CheckUserInMemberGroupCmdImpl { /** * For this example, the simple condition variable name is defined as * a string of "loyalty". In practice, this constant should be defined in * a separate constant class. */ public static final String VARIABLE_LOYALTY_POINTS = "loyalty"; /** * Override the parent's method to evaluate the loyalty points * simple condition. * @return <code>true</code> if the condition evaluates to true. */ public boolean evaluate( String variable, String operator, String value, SimpleCondition.Qualifier[] qualifiers) { boolean result = false; if (VARIABLE_LOYALTY_POINTS.equals(variable)) { // If the simple condition is for loyalty points, // invoke the specific loyalty points evaluation // method to handle the case. result = evaluateLoyaltyPointsCondition(operator, value, qualifiers); } else { // Since we override this evaluate() method from // the parent class to take care of the new loyalty // points condition, call the parent's // evaluate() method to handle all the other simple // conditions. result = super.evaluate(variable, operator, value, qualifiers); } return result; } /** * Evaluate the loyalty points condition. */ protected boolean evaluateLoyaltyPointsCondition( String operator, String value, SimpleCondition.Qualifier[] qualifiers) { Integer numOfPoints = null; try { // To simplify this example, assume the loyalty points // value is stored in the table USERDEMO in the // customizable column FIELD6. We can use the parent's // class method getDemographics() to retrieve the access // bean that contains the USERDEMO information. if (getDemographics() != null) { // uncomment one of the lines below depending on whether the environment is v7, v8, or v91+ // numOfPoints = getDemographics().getField6InEJBType(); // v7 and v8 code // numOfPoints = getDemographics().getField6InEntityType(); // v91+ code code numOfPoints = getDemographics().getField6InEntityType(); // v91+ code code } } catch (Exception e) { // Handle the exception here. } // Call the ConditionUtil helper class's evaluateInteger() // method to evaluate the loyalty points integer value // with the given operator. return ConditionUtil.evaluateInteger (numOfPoints, operator, SegmentUtil.toInteger(value)); } }//end-ExtCheckUserInMemberGroupCmdImpl - Save and close the new implementation class file.
-
Register the task command in the CMDREG table: