Elastic Path Commerce Development

Tag value types

Tag value types

A tag value type is a high-level data type for tags. It is used to configure supported Tag operators, Tag validation, and Allowed tag values. Every tag must be associated with one and only one tag value type.

Tag value types are defined in the TTAGVALUETYPE table. The following types are provided out-of-the-box:

Tag value type Description Data type Validation constraint

time

The date/time in 13-digit Java format

java.lang.Long

None

age

A person's age

java.lang.Integer

Must be between 0 and 120

gender

A person's gender

java.lang.String

Must be either M or F (case-sensitive)

text

Free-form text

java.lang.String

None

money

A currency value

java.lang.BigDecimal

Must be a non-negative decimal

time_zone

description

java.lang.Float

Must be a float

category

description

java.lang.String

None

country_code

description

java.lang.String

None

ip_routing_type

description

java.lang.String

None

ip_connection_type

description

java.lang.String

None

continent

description

java.lang.String

None

state

description

java.lang.String

None

city

description

java.lang.String

None

domain_name

description

java.lang.String

None

zip_code

description

java.lang.String

Must be less than or equal to 10 characters

search_phrase

description

java.lang.String

None

Allowed tag values

You can specify what values are allowed for your custom Tag value types. Allowed tag values are defined in the TTAGALLOWEDVALUE table.

For example, you want to create a marital status tag to store each customer's marital status. The possible values would be single, married, divorced, widowed, or common law. You could use the out-of-the-box text tag value type, but that would allow CM users to enter invalid values when creating conditions with this tag. A better way would be to define a marital status tag value type that would only allow users to enter specific values. The following SQL creates the tag value type.

insert into TTAGVALUETYPE(uidpk, guid, java_type) values(17, 'maritalStatus', 'java.lang.String');

The following SQL defines the operators that are available to users when creating condition statements with tags of this type.

insert into TTAGVALUETYPEOPERATOR(tagvaluetype_guid, tagoperator_guid)
	values('maritalStatus', 'equalTo'), ('maritalStatus', 'notEqualTo');

The following SQL sets the values that are allowed for the tag value type.

insert into TTAGALLOWEDVALUE(uidpk, value, tagvaluetype_guid, description, ordering)
	values(42, 'single', 'maritalStatus', 'Single', 1),
	(43, 'married', 'maritalStatus', 'Married', 2),
	(44, 'divorced', 'maritalStatus', 'Divorced', 3),
	(45, 'widowed', 'maritalStatus', 'Widowed', 4),
	(46, 'common law', 'maritalStatus', 'Common law', 5);

In the CM's serviceCM.xml file, find the selectableTagValueServiceLocator bean definiton and add the following value provider:

<entry><key><value>maritalStatus</value></key>
        <bean class="com.elasticpath.tags.service.impl.InternalSelectableStringTagValueProviderImpl"></bean>
</entry>

When a user creates a condition statement with this tag, the condition builder UI displays a drop-down list containing only the allowed values.

Tag operators

You can specify what operators are supported by Tag value types. The following tag operators are provided out of the box:

Tag operator GUID Description Supported data types

equalTo

Checks if the tag value is equal to the value. For strings, this is a case-sensitive comparison.

strings and numbers

notEqualTo

Checks if the tag value is equal to the value. For strings, this is a case-sensitive comparison.

strings and numbers

includes

Checks if the tag value contains the string. This is a case-sensitive comparison.

strings

notIncludes

Checks if the tag value does not contain the string. This is a case-sensitive comparison.

strings

equalsIgnoreCase

Checks if the tag value is equal to the string. This is a case-insensitive comparison.

strings

includesIgnoreCase

Checks if the tag value contains the string. This is a case-insensitive comparison.

strings

lessThan

Checks if the tag value is less than the number.

numbers

greaterThan

Checks if the tag value is greater than the number.

numbers

lessThanOrEqualTo

Checks if the tag value is less than or equal to the number.

numbers

greaterThanOrEqualTo

Checks if the tag value is greater than or equal to the number.

numbers

notEqualsIgnoreCase

Checks if the tag value is not equal to the value. This is a case-insensitive comparison.

strings and numbers

notIncludesIgnoreCase

Checks if the tag value contains the string. This is a case-insensitive comparison.

strings

The following SQL associates a tag operator with a tag value type.

insert into TTAGVALUETYPEOPERATOR(tagvaluetype_guid, tagoperator_guid)
     values('phone_number', 'includes'),
          ('phone_number', 'greaterThan'),
         ('phone_number', 'lessThan'),
          ('phone_number', 'notIncludes');

Tag validation

You can specify validation constraints on Tag value types to prevent users from setting invalid tag values. Validation constraints are stored as strings in the TVALIDATIONCONSTRAINTS table. They are expressed in the Spring Expression Language format (also called SpEL), which provides a rich yet easy to learn syntax for defining validation rules.

For example, you want to create a tag to store North American telephone numbers (XXX-XXX-XXXX). The following SQL creates the tag value type and its supported operators.

insert into TTAGVALUETYPE(uidpk, guid, java_type)
     values(17, 'phone_number', 'java.lang.String');

insert into TTAGVALUETYPEOPERATOR(tagvaluetype_guid, tagoperator_guid)
     values('phone_number', 'includes'),
          ('phone_number', 'greaterThan'),
         ('phone_number', 'lessThan'),
          ('phone_number', 'notIncludes');

The following SQL creats the validation constraint that will be used to determine whether the user input is valid.

insert into TVALIDATIONCONSTRAINTS(uidpk, object_uid, error_message_key, validation_constraint, type)
    values(17, 17, 'validationTagPhoneNumberError',
    '(#isValidConditionType((#this))) == true AND tagValue.matches(\'[2-9]\\\\d{2}-\\\\d{3}-\\\\d{4}\')',
    'TagValueType');

The validation_constraint column contains the SpEL code that is used to evaluate the user input. In this case, it tests the user input against a regular expression.