# Discount Predicate Field Identifiers Certain resources have a `predicate` or `cartPredicate` field. In particular, [Product Discounts](https://docs.commercetools.com/api/projects/productDiscounts.md), [Cart Discounts](https://docs.commercetools.com/api/projects/cartDiscounts.md), and [Shipping Method](https://docs.commercetools.com/api/projects/shippingMethods.md) have predicate fields. This field expects a conditional statement known as a predicate. When a predicate evaluates as true, the API applies the discount or selects a shipping method. Predicates consist of field identifiers and operators. For more information on creating predicates, see [Discount Predicate Operators](https://docs.commercetools.com/api/predicates/predicate-operators.md). The field identifiers on this page apply only to Discount and Cart predicates, which are set in the `predicate` and `cartPredicate` fields. They use a dotted syntax (for example, `attributes.`) that is not valid in [Query Predicates](https://docs.commercetools.com/api/predicates/query.md) and returns a [400 Bad Request](https://docs.commercetools.com/api/errors.md#400-bad-request) error when used with the `where` query parameter. The underlying data is still filterable in `where` queries using parenthesis for nesting values. For example, to filter Carts or Orders by a Line Item's Product Variant Attribute, use `lineItems(variant(attributes(name="…" and value=…)))`. For more information, see [Query Predicates on Attributes](https://docs.commercetools.com/api/predicates/query.md#on-attributes). ## MoneyString A string representation of the money value in cent precision followed by the currency code compliant to [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217), for example, `42000.00 USD`. Only the dot separator is allowed to divide the base monetary unit and the cents. Other separators, like for grouping thousands and millions, are not supported. ## ProductDiscount predicates ProductDiscount predicates reference a field on a [Product](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AProduct) for specifying [Product Discounts](https://docs.commercetools.com/api/projects/productDiscounts.md). ### Product field identifiers The following identifiers reference fields on a [Product](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AProduct). - `product.id` - String - `product.key` - String - `productType.id` - String - `productType.key` - String - `variant.id` - Number - `variant.key` - String - `sku` - String - `attributes.` Matches Product Attributes and Variant Attributes by their respective names. For more information, see [Attribute Field Identifiers](https://docs.commercetools.com/api/projects/predicates.md#attribute-field-identifiers). ### Price field identifiers The following identifiers reference price fields from both [Embedded Prices](https://docs.commercetools.com/api/types.md#price) and [StandalonePrices](https://docs.commercetools.com/api/projects/standalone-prices.md#standaloneprice) of a product, regardless of the [Product's](https://docs.commercetools.com/api/projects/products.md#product) `priceMode` value. - `price` - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) - `amount` - Number - The amount in the specified `currency`. - `centAmount` - Number - The amount in cents (the subunit) of the specified `currency`. - `currency`- [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `country` - [CountryCode](https://docs.commercetools.com/api/types.md#countrycode) - `customerGroup.id` - String - `customerGroup.key` - String - `channel.id` - String - `channel.key` - String ### Category field identifiers The following identifiers identify products that have a specific [Category](https://docs.commercetools.com/api/projects/categories.md) or group of categories. - `categories.id` - Array of Strings Identifies all Products that have a category. - `categories.key` - Array of Strings Identifies all Products that have a category with a given key. - `categoriesWithAncestors.id` - Array of Strings Identifies all Products that have a category as well as products in child categories. - `categoriesWithAncestors.key` - Array of Strings Identifies all Products that have a category as well as products in child categories that have a given key. ### Attribute field identifiers The following identifiers reference user-defined attribute fields on a [Product](https://docs.commercetools.com/api/projects/products.md). - `attribute.name` - [Attribute](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AAttribute) Matches Product Attributes and Variant Attributes by their respective names. If a field name contains a dash (-) or starts with a digit, escape it using backticks (\`): ``attributes.\`2019Season\` `` #### Supported Attribute Types The following [attribute types](https://docs.commercetools.com/api/projects/productTypes.md#attributetype) are supported as individual values or as [Sets](https://docs.commercetools.com/api/projects/productTypes.md#attributesettype): - `boolean` - `text` - `number` - `datetime` - `date` - `time` - `enum` - `lenum` - `money` For `enum` and `lenum` attributes, you can only reference a value in the collection using the value's `key` field. ### Product Predicate examples ```javascript // matches a specific variant in the specific product product.id = "f6a19a23-14e3-40d0-aee2-3e612fcb1bc7" and variant.id = 1 // matches a specific variant based on variant key in the specific product (product.id = "f6a19a23-14e3-40d0-aee2-3e612fcb1bc7" and variant.id = 1) or variant.key = "blue_shirt" // matches a product that is only in the given category categories.id = "f6a19a23-14e3-40d0-aee2-3e612fcb1bc7" //matches a product that is in the given category categories.id contains "f6a19a23-14e3-40d0-aee2-3e612fcb1bc7" //matches a product that is in all of the given categories categories.id contains all ("f6a19a23-14e3-40d0-aee2-3e612fcb1bc7", "abcd9a23-14e3-40d0-aee2-3e612fcbefgh") //matches a product that is in one of the given categories categories.id contains any ("f6a19a23-14e3-40d0-aee2-3e612fcb1bc7", "abcd9a23-14e3-40d0-aee2-3e612fcbefgh") //matches a product that is not in one of the given categories not(categories.id contains any ("f6a19a23-14e3-40d0-aee2-3e612fcb1bc7","abcd9a23-14e3-40d0-aee2-3e612fcbefgh")) //matches a product that is in the two given categories and in no others categories.id = ("f6a19a23-14e3-40d0-aee2-3e612fcb1bc7", "abcd9a23-14e3-40d0-aee2-3e612fcbefgh") //matches a product that is not in a given category categories.id != ("f6a19a23-14e3-40d0-aee2-3e612fcb1bc7") //matches the prices above 12€ for any countries except France that do not have a customer group set centAmount > 1200 and currency = "EUR" and country != "FR" and customerGroup.id is not defined //matches all Products that have size "L" and have the color white and black. //if the `attribute` is a Product Attribute, then the predicate will apply to all variants of the Product. //if you want to match a specific variant of a Product, then use a Variant Attribute. //size is an EnumType attribute for which the key is specified in the predicate, //color is a SetType of Enums for which the keys are listed in the predicate. attributes.size = "L" and attributes.colors contains all ("black", "white") //matches all Products with the given sku, the available boolean Attribute is set as true, and the Attribute weight number is lesser than 100. //if the `attribute` is a Product Attribute, then the predicate will apply to all variants of the Product. //if you want to match a specific variant of a Product, then use a Variant Attribute. sku = "AB-12" and attributes.available = true and attributes.weight < 100 //matches all products that are in the given category or in a category that is a descendant of the given category categoriesWithAncestors.id contains "abcd9a23-14e3-40d0-aee2-3e612fcbefgh" ``` ## Cart Predicates Cart Predicate field identifiers reference fields on a Cart. You can also use [Cart Predicate Functions](https://docs.commercetools.com/api/projects/predicates.md#cart-predicate-functions) to construct conditional statements based on the state of the cart and its line items. You can use Cart Predicates for the following: - [Cart Discounts](https://docs.commercetools.com/api/projects/cartDiscounts.md) [Cart Discounts](https://docs.commercetools.com/api/projects/cartDiscounts.md) can have multiple predicates: a `cartPredicate` and one or more [CartDiscountTarget](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACartDiscountTarget) predicates. - [Shipping Methods](https://docs.commercetools.com/api/projects/shippingMethods.md) ### Cart field identifiers The following identifiers reference fields on a [Cart](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACart). - `currency` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `country` - [CountryCode](https://docs.commercetools.com/api/types.md#countrycode) - `origin` - [CartOrigin](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACartOrigin) - `store.key` - `key` of a [Store](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AStore) Can only be used for [Shipping Predicates](https://docs.commercetools.com/api/shipping-delivery-overview.md#predicates). - `totalPrice` - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) - `totalPrice.centAmount` - Number - `totalPrice.currencyCode` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `taxedPrice.net` - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) - `taxedPrice.net.centAmount` - Number - `taxedPrice.net.currencyCode` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `taxedPrice.gross` - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) - `taxedPrice.gross.centAmount` - Number - `taxedPrice.gross.currencyCode` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `createdAt` - [DateTime](https://docs.commercetools.com/api/types.md#datetime) - `lastModifiedAt` - [DateTime](https://docs.commercetools.com/api/types.md#datetime) - `shippingAddress` - [Address field identifier](https://docs.commercetools.com/api/projects/predicates.md#address-field-identifiers) - `billingAddress` - [Address field identifier](https://docs.commercetools.com/api/projects/predicates.md#address-field-identifiers) - `custom.` - [CustomField](https://docs.commercetools.com/api/projects/custom-fields.md#customfields) Matches a Custom Field by its name. For more information, see [CustomField Predicate Field Identifiers](https://docs.commercetools.com/api/projects/predicates.md#customfield-field-identifiers). - `custom.type.id` - `id` of a [Type](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AType) - `custom.type.key` - `key` of a [Type](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AType) ### Customer field identifiers The following identifiers reference fields on a [Cart](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACart)'s [Customer](https://docs.commercetools.com/api/projects/customers.md). Except `customer.email`, for all predicates to take effect, the Cart `customerId` field must be set. - `customer.id` - String - `customer.key` - String - `customer.customerNumber` - String - `customer.email` - String For the predicate to take effect, the Cart `customerEmail` field must be set. - `customer.customerGroup.id` - String For the predicate to take effect, the Cart `customerId` or `customerGroup` field must be set. - `customer.customerGroup.key` - String For the predicate to take effect, the Cart `customerId` or `customerGroup` field must be set. - `customer.customerGroupAssignments.customerGroup.id` - Array of Strings - `customer.customerGroupAssignments.customerGroup.key` - Array of Strings - `customer.firstName` - String - `customer.lastName` - String - `customer.middleName` - String - `customer.title` - String - `customer.isEmailVerified` - Boolean - `customer.externalId` - String - `customer.createdAt` - [DateTime](https://docs.commercetools.com/api/types.md#datetime) - `customer.lastModifiedAt` - [DateTime](https://docs.commercetools.com/api/types.md#datetime) ### Business Unit field identifiers The following identifiers reference fields on a [Cart](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACart)'s [Business Unit](https://docs.commercetools.com/api/projects/business-units.md). For Business Unit fields to apply as predicates, `businessUnit` must be defined on the [Cart](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACart). - `businessUnit.customerGroupAssignments.customerGroup.id` - Array of Strings - `businessUnit.customerGroupAssignments.customerGroup.key` - Array of Strings ### ShippingInfo field identifiers The following identifiers reference fields on a [Cart](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACart)'s [ShippingInfo](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AShippingInfo). To match against Carts with multiple Shipping Methods, you must construct your predicate using the [Cart Predicate functions](https://docs.commercetools.com/api/projects/predicates.md#cart-predicate-functions) `shippingInfoExists` or `forAllShippingInfos`. - `shippingInfo.shippingMethod.id` - String - `shippingInfo.shippingMethod.key` - String - `shippingInfo.shippingMethodName` - String - `shippingInfo.price` - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) - `shippingInfo.price.centAmount` - Number - `shippingInfo.price.currencyCode` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `shippingInfo.shippingRate.price` - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) - `shippingInfo.shippingRate.price.centAmount` - Number - `shippingInfo.shippingRate.price.currencyCode` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `shippingInfo.shippingRate.freeAbove` - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) - `shippingInfo.shippingRate.freeAbove.centAmount` - Number - `shippingInfo.shippingRate.freeAbove.currencyCode` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `shippingInfo.taxCategory.id` - String - `shippingInfo.taxCategory.key` - String - `shippingInfo.taxRate` - [TaxRate field identifiers](https://docs.commercetools.com/api/projects/predicates.md#taxrate-field-identifiers) ### Address field identifiers The following identifiers reference fields on a [Cart](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACart)'s `shippingAddress` or `billingAddress` [Address](https://docs.commercetools.com/api/types.md#address) fields. Depending on the address you want to construct a predicate with, replace `` with `shippingAddress` or `billingAddress`. - `.id` - String - `.key` - String - `.title` - String - `.salutation` - String - `.firstName` - String - `.lastName` - String - `.streetName` - String - `.streetNumber` - String - `.additionalStreetInfo` - String - `.postalCode` - String - `.city` - String - `.region` - String - `.state` - String - `.country` - [CountryCode](https://docs.commercetools.com/api/types.md#countrycode) - `.company` - String - `.department` - String - `.building` - String - `.apartment` - String - `.pOBox` - String - `.phone` - String - `.mobile` - String - `.email` - String - `.additionalAddressInfo` - String ### TaxRate field identifiers The following identifiers reference fields on a [Cart](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACart)'s [TaxRate](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ATaxRate) field. - `taxRate.id` - String - `taxRate.name` - String - `taxRate.amount` - Number - `taxRate.includedInPrice` - Boolean - `taxRate.country` - [CountryCode](https://docs.commercetools.com/api/types.md#countrycode) - `taxRate.state` - String ### LineItem field identifiers The following identifiers reference fields on a [Cart](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACart)'s [LineItems](https://docs.commercetools.com/api/projects/carts.md#lineitem). You can only use LineItem predicate field identifiers for the following: - [Cart Discounts](https://docs.commercetools.com/api/projects/cartDiscounts.md) with a `lineItem` [CartDiscountTarget](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACartDiscountTarget) - As a part of a [Cart Predicate Function](https://docs.commercetools.com/api/projects/predicates.md#cart-predicate-functions). You cannot use LineItem predicates by themselves in a [CartDiscount](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACartDiscount). - `product.id` - String - `product.key` - String - `productType.id` - String - `productType.key` - String - `variant.id` - Number - `variant.key` - String - `sku` - String - `categories.id` - Array of Strings - `categories.key` - Array of Strings - `categoriesWithAncestors.id` - Array of Strings Identifies categories of a product and all the ancestors of those categories. It is used to match all categories that are in a subtree of a specific category. - `categoriesWithAncestors.key` - Array of Strings Identifies categories of a product and all the ancestors of those categories. It is used to match all categories that are in a subtree of a specific category by key. - `attributes.` Matches an Attribute by its name. For more information, see [Attribute Field Identifiers](https://docs.commercetools.com/api/projects/predicates.md#attribute-field-identifiers). - `custom.` - [CustomField](https://docs.commercetools.com/api/projects/custom-fields.md#customfields) Matches a Custom Field on the line item by its name. For more information, see [CustomField Field Identifiers](https://docs.commercetools.com/api/projects/predicates.md#customfield-field-identifiers) - `custom.type.id` - `id` of a [Type](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AType) - `custom.type.key` - `key` of a [Type](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AType) - `taxRate` - [TaxRate field identifiers](https://docs.commercetools.com/api/projects/predicates.md#taxrate-field-identifiers) - `supplyChannel.id` - String - `supplyChannel.key` - String - `quantity` - Number This field cannot be used in predicates for [MultiBuyLineItemsTarget](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AMultiBuyLineItemsTarget) or [CartDiscountPatternTarget](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACartDiscountPatternTarget) predicates. - `price` - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) The product price without any cart discounts applied. - `price.centAmount` - Number - `price.currencyCode` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `price.discount.id` - String - `price.country` - [CountryCode](https://docs.commercetools.com/api/types.md#countrycode) - `price.customerGroup.id` - String - `price.customerGroup.key` - String - `price.channel.id` - String - `price.channel.key` - String #### LineItem predicate examples ```javascript // matches all line items true // matches line item with SKU "SKU-123" only if the price is a net price sku = "SKU-123" and taxRate.includedInPrice = false // matches a line item by product type, a specific product and at least 3 'rating' attributes productType.id = "f6a19a23-14e3-40d0-aee2-3e612fcb1bc7" and attributes.rating > 3 and (product.id = "abcd9a23-14e3-40d0-aee2-3e612fcbefgh" or product.id = "ba3e4ee7-30fa-400b-8155-46ebf423d793") // matches a line item that has the Custom Field "gender" to be "alien" custom.gender = "alien" // matches a line item that is only in the given category categories.id = "f6a19a23-14e3-40d0-aee2-3e612fcb1bc7" //matches a line item that is in the given category categories.id contains "f6a19a23-14e3-40d0-aee2-3e612fcb1bc7" //matches a line item that is in all of the given categories categories.id contains all ("f6a19a23-14e3-40d0-aee2-3e612fcb1bc7", "abcd9a23-14e3-40d0-aee2-3e612fcbefgh") //matches a line item that is in one of the given categories categories.id contains any ("f6a19a23-14e3-40d0-aee2-3e612fcb1bc7", "abcd9a23-14e3-40d0-aee2-3e612fcbefgh") //matches a line item that is not in one of the given categories not(categories.id contains any ("f6a19a23-14e3-40d0-aee2-3e612fcb1bc7","abcd9a23-14e3-40d0-aee2-3e612fcbefgh")) //matches a line item that is in the two given categories and in no others categories.id = ("f6a19a23-14e3-40d0-aee2-3e612fcb1bc7", "abcd9a23-14e3-40d0-aee2-3e612fcbefgh") //matches a line item that is not in a given category categories.id != ("f6a19a23-14e3-40d0-aee2-3e612fcb1bc7") ``` ### CustomLineItem field identifiers The following identifiers reference fields on a [Cart](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACart)'s [CustomLineItems](https://docs.commercetools.com/api/projects/carts.md#customlineitem). You can only use CustomLineItem predicate field identifiers for the following: - [Cart Discounts](https://docs.commercetools.com/api/projects/cartDiscounts.md) with a `customLineItem` [CartDiscountTarget](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACartDiscountTarget) - As a part of a [Cart Predicate Function](https://docs.commercetools.com/api/projects/predicates.md#cart-predicate-functions). You cannot use CustomLineItem predicates by themselves in a [CartDiscount](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACartDiscount). - `money` - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) - `money.centAmount` - Number - `money.currencyCode` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `slug` - String - `quantity` - Number This field cannot be used in predicates for [MultiBuyCustomLineItemsTarget](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AMultiBuyCustomLineItemsTarget) or [CartDiscountPatternTarget](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACartDiscountPatternTarget) predicates. - `price` - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) - `taxCategory.id` - String - `taxCategory.key` - String - `taxRate` - [TaxRate field identifiers](https://docs.commercetools.com/api/projects/predicates.md#taxrate-field-identifiers) - `custom.` - [CustomField](https://docs.commercetools.com/api/projects/custom-fields.md#customfields) Matches a Custom Field on the custom line item by its name given a certain [predicate](https://docs.commercetools.com/api/projects/predicates.md#customfield-field-identifiers). - `custom.type.id` - `id` of a [Type](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AType) - `custom.type.key` - `key` of a [Type](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AType) #### CustomLineItem predicate examples ```javascript // matches all custom line items true // matches custom line items with price of individual items greater than 10.50 EUR only if the price is a net price money > "10.50 EUR" and taxRate.includedInPrice = false // matches a custom line item by slug slug = "adidas-superstar-2" // matches a custom line item that has the Custom Field "gender" to be "alien" custom.gender = "alien" ``` ### CustomField field identifiers The following identifiers reference Custom Fields on a [Cart](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACart), or a line item in a cart. You can use CustomField field identifiers for the following: - A Cart's `cartPredicate` field, to identify Custom Fields on a Cart. - A CartDiscount with a `lineItem` [CartDiscountTarget](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACartDiscountTarget), to identify Custom Fields on a LineItem. - A CartDiscount with a `customLineItem` [CartDiscountTarget](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACartDiscountTarget), to identify Custom Fields on a CustomLineItem. - `custom.` - [CustomField](https://docs.commercetools.com/api/projects/custom-fields.md#customfields) Matches a Custom Field by its name. If a field name contains a dash (-) or starts with a digit, escape it using backticks (\`): `` custom.\`1stYear\` `` #### Supported Custom Field types The following [field types](https://docs.commercetools.com/api/projects/types.md#fieldtype) are supported as individual values or as [Sets](https://docs.commercetools.com/api/projects/types.md#customfieldsettype): - `Boolean` - `String` - `Number` - `DateTime` - `Date` - `Time` - `Enum` - `LocalizedEnum` - `Reference` Custom Fields using the `Money` type are also supported, but [Sets](https://docs.commercetools.com/api/projects/types.md#customfieldsettype) with the `Money` type are not supported. #### CustomField predicate examples Predicates on a `reference` match on the ID. Examples: ```javascript //identifies a Custom Field by ID (where the field is a Reference type) custom. = "" //checks if a Custom Field is contained in a collection, where the field is a reference type custom. contains any ("", "") //checks if a Custom Field has a value equal to 18.00 EUR, if the field is a Money type custom. = "18.00 EUR" //checks if custom..centAmount = 18 //checks if custom..currencyCode = "EUR" ``` ### Cart Predicate functions In addition to accessing specific field information, you can use the following predicate functions when constructing Cart Predicates. All functions accept a [LineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#lineitem-field-identifiers), [CustomLineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#customlineitem-field-identifiers), or [ShippingInfoPredicate](https://docs.commercetools.com/api/projects/predicates.md#shippinginfo-field-identifiers) as an argument, which allows you to limit function to a subset of matching (custom) line items or shipping infos. You can also provide a simple predicate, like `true`, as an argument if you want to sum or count all (custom) line items or shipping infos. - `lineItemCount`(`predicate`: [LineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#lineitem-field-identifiers)) – Number Counts matching line items. - `customLineItemCount`(`predicate`: [CustomLineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#customlineitem-field-identifiers)) – Number Counts matching custom line items. - `lineItemTotal`(`predicate`: [LineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#lineitem-field-identifiers)) – [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) Sums the total of matching line items. The total of a line item depends on the [Line Item price mode](https://docs.commercetools.com/api/projects/carts.md#lineitempricemode) and the discounts that might apply. - `customLineItemTotal`(`predicate`: [CustomLineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#customlineitem-field-identifiers)) – [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) Sums the `quantity * money` of matching custom line items. - `lineItemNetTotal`(`predicate`: [LineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#lineitem-field-identifiers)) – [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) Sums the total of matching line items only if the price is a net price (only valid for tax-exclusive `taxRate`). - `customLineItemNetTotal`(`predicate`: [CustomLineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#customlineitem-field-identifiers)) – [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) Sums the `quantity * money` of matching custom line items only if the price is a net price (only valid for tax-exclusive `taxRate`). - `lineItemGrossTotal`(`predicate`: [LineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#lineitem-field-identifiers)) – [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) Sums the total of matching line items only if the price is a gross price (only valid for tax-inclusive `taxRate`). - `customLineItemGrossTotal`(`predicate`: [CustomLineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#customlineitem-field-identifiers)) – [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) Sums the `quantity * money` of matching custom line items only if the price is a gross price (only valid for tax-inclusive `taxRate`). - `lineItemExists`(`predicate`: [LineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#lineitem-field-identifiers)) – Boolean Returns true if at least one line item matches the predicate, otherwise false. - `forAllLineItems`(`predicate`: [LineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#lineitem-field-identifiers)) – Boolean Returns true if all line items match the predicate or a cart is empty, otherwise false. To return false for an empty cart, use the function in combination with `lineItemExists`. - `shippingInfoExists`(`predicate`: [ShippingInfoPredicate](https://docs.commercetools.com/api/projects/predicates.md#shippinginfo-field-identifiers)) – Boolean Returns true if at least one shipping info matches the predicate, otherwise false. - `forAllShippingInfos`(`predicate`: [ShippingInfoPredicate](https://docs.commercetools.com/api/projects/predicates.md#shippinginfo-field-identifiers)) – Boolean Returns true if all shipping infos match the predicate, otherwise false. ### Cart Predicate examples ```javascript // matches a cart with total line item cost greater than or equal to 10 USD (which excludes other costs, like shipping) lineItemTotal(true) >= "10.00 USD" // matches a cart only when it has exactly 2 line items that have product with size "xxl" or "xl" lineItemCount(attributes.size in ("xxl", "xl")) = 2 // matches a cart by customer information customer.email = "john@example.com" and customer.customerGroup.id = "f6a19a23-14e3-40d0-aee2-3e612fcb1bc7" // matches a cart with a minimum total price and at least one lineItem that satisfies a price, a productType, a size attribute or a specific product totalPrice > "800.00 EUR" and lineItemCount(price > "10.50 EUR" and productType.id = "f6a19a23-14e3-40d0-aee2-3e612fcb1bc7" and attributes.size in ("xl", "xxl") or product.id = "abcd9a23-14e3-40d0-aee2-3e612fcbefgh") > 0 // matches a cart with custom.bookingStart = 2016-11-24 and custom.bookingEnd = 2016-12-04 custom.bookingStart = "2016-11-24" and custom.bookingEnd = "2016-12-04" // matches a cart for a family (at least 2 adults and at least one youth) lineItemCount(custom.age = "adult") >=2 and lineItemCount(custom.age = "youth") >=1 // matches a cart with total line item cost lesser than or equal to 55 USD if the line items are not in one of the given categories and does not have 1234 as SKU lineItemTotal(not(categories.id contains any ("SALE","NEW")) and sku != "1234") <= "55.00 USD" // matches a cart if all line items match the predicate, otherwise false (for empty carts too) forAllLineItems() and lineItemExists() ``` ## Order Predicates Order Predicate field identifiers reference fields on an Order. You can also use [Order Predicate Functions](https://docs.commercetools.com/api/projects/predicates.md#order-predicate-functions) to construct conditional statements based on the state of the cart and its line items. You can use Order Predicates for the following: - [Approval Rules](https://docs.commercetools.com/api/projects/approval-rules.md) ### Order field identifiers The following identifiers reference fields on a [Order](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AOrder). - `currency` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `country` - [CountryCode](https://docs.commercetools.com/api/types.md#countrycode) - `totalPrice` - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) - `totalPrice.centAmount` - Number - `totalPrice.currencyCode` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `taxedPrice.net` - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) - `taxedPrice.net.centAmount` - Number - `taxedPrice.net.currencyCode` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `taxedPrice.gross` - String - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) - `taxedPrice.gross.centAmount` - Number - `taxedPrice.gross.currencyCode` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `createdAt` - [DateTime](https://docs.commercetools.com/api/types.md#datetime) - `lastModifiedAt` - [DateTime](https://docs.commercetools.com/api/types.md#datetime) - `shippingAddress` - [Address field identifiers](https://docs.commercetools.com/api/projects/predicates.md#address-field-identifiers) - `billingAddress` - [Address field identifiers](https://docs.commercetools.com/api/projects/predicates.md#address-field-identifiers) - `custom.` - [CustomField](https://docs.commercetools.com/api/projects/custom-fields.md#customfields) Matches a Custom Field by its name. For more information, see [CustomField Predicate Field Identifiers](https://docs.commercetools.com/api/projects/predicates.md#customfield-field-identifiers). - `custom.type.id` - `id` of a [Type](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AType) - `custom.type.key` - `key` of a [Type](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AType) ### Customer field identifiers The following identifiers reference fields on a [Order](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AOrder)'s [Customer](https://docs.commercetools.com/api/projects/customers.md). - `customer.id` - String - `customer.key` - String - `customer.email` - String - `customer.customerNumber` - String - `customer.customerGroup.id` - String - `customer.customerGroup.key` - String - `customer.firstName` - String - `customer.lastName` - String - `customer.middleName` - String - `customer.title` - String - `customer.isEmailVerified` - Boolean - `customer.externalId` - String - `customer.createdAt` - [DateTime](https://docs.commercetools.com/api/types.md#datetime) - `customer.lastModifiedAt` - [DateTime](https://docs.commercetools.com/api/types.md#datetime) ### ShippingInfo field identifiers The following identifiers reference fields on a [Order](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AOrder)'s [ShippingInfo](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AShippingInfo). - `shippingInfo.shippingMethod.id` - String - `shippingInfo.shippingMethod.key` - String - `shippingInfo.shippingMethodName` - String - `shippingInfo.price` - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) - `shippingInfo.price.centAmount` - Number - `shippingInfo.price.currencyCode` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `shippingInfo.shippingRate.price` - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) - `shippingInfo.shippingRate.price.centAmount` - Number - `shippingInfo.shippingRate.price.currencyCode` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `shippingInfo.shippingRate.freeAbove` - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) - `shippingInfo.shippingRate.freeAbove.centAmount` - Number - `shippingInfo.shippingRate.freeAbove.currencyCode` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `shippingInfo.taxCategory.id` - String - `shippingInfo.taxCategory.key` - String - `shippingInfo.taxRate` - [TaxRate field identifiers](https://docs.commercetools.com/api/projects/predicates.md#taxrate-field-identifiers) ### Address field identifiers The following identifiers reference fields on a [Order](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AOrder)'s `shippingAddress` or `billingAddress` [Address](https://docs.commercetools.com/api/types.md#address) fields. Depending on the address you want to construct a predicate with, replace `` with `shippingAddress` or `billingAddress`. - `.id` - String - `.key` - String - `.title` - String - `.salutation` - String - `.firstName` - String - `.lastName` - String - `.streetName` - String - `.streetNumber` - String - `.additionalStreetInfo` - String - `.postalCode` - String - `.city` - String - `.region` - String - `.state` - String - `.country` - [CountryCode](https://docs.commercetools.com/api/types.md#countrycode) - `.company` - String - `.department` - String - `.building` - String - `.apartment` - String - `.pOBox` - String - `.phone` - String - `.mobile` - String - `.email` - String - `.additionalAddressInfo` - String ### TaxRate field identifiers The following identifiers reference fields on a [Order](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AOrder)'s [TaxRate](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ATaxRate) field. - `taxRate.id` - String - `taxRate.name` - String - `taxRate.amount` - Number - `taxRate.includedInPrice` - Boolean - `taxRate.country` - [CountryCode](https://docs.commercetools.com/api/types.md#countrycode) - `taxRate.state` - String ### LineItem field identifiers The following identifiers reference fields on a [Order](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AOrder)'s [LineItems](https://docs.commercetools.com/api/projects/carts.md#lineitem). You can only use LineItem predicate field identifiers for the following: - As a part of a [Order Predicate Function](https://docs.commercetools.com/api/projects/predicates.md#order-predicate-functions). - `product.id` - String - `product.key` - String - `productType.id` - String - `productType.key` - String - `variant.id` - Number - `variant.key` - String - `sku` - String - `categories.id` - Array of Strings - `categories.key` - Array of Strings - `categoriesWithAncestors.id` - Array of Strings Identifies categories of a product and all the ancestors of those categories. It is used to match all categories that are in a subtree of a specific category. - `categoriesWithAncestors.key` - Array of Strings Identifies categories of a product and all the ancestors of those categories. It is used to match all categories that are in a subtree of a specific category by key. - `attributes.` Matches an Attribute by its name. For more information, see [Attribute Field Identifiers](https://docs.commercetools.com/api/projects/predicates.md#attribute-field-identifiers). - `custom.` - [CustomField](https://docs.commercetools.com/api/projects/custom-fields.md#customfields) Matches a Custom Field on the line item by its name. For more information, see [CustomField Field Identifiers](https://docs.commercetools.com/api/projects/predicates.md#customfield-field-identifiers) - `custom.type.id` - `id` of a [Type](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AType) - `custom.type.key` - `key` of a [Type](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AType) - `taxRate` - [TaxRate field identifiers](https://docs.commercetools.com/api/projects/predicates.md#taxrate-field-identifiers) - `supplyChannel.id` - String - `supplyChannel.key` - String - `quantity` - Number This field cannot be used in predicates for [MultiBuyLineItemsTarget](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AMultiBuyLineItemsTarget) or [CartDiscountPatternTarget](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACartDiscountPatternTarget) predicates. - `price` - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) The product price without any cart discounts applied. - `price.centAmount` - Number - `price.currencyCode` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `price.discount.id` - String - `price.country` - [CountryCode](https://docs.commercetools.com/api/types.md#countrycode) - `price.customerGroup.id` - String - `price.customerGroup.key` - String - `price.channel.id` - String - `price.channel.key` - String #### LineItem predicate examples ```javascript // matches all line items true // matches line item with SKU "SKU-123" only if the price is a net price sku = "SKU-123" and taxRate.includedInPrice = false // matches a line item by product type, a specific product and at least 3 'rating' attributes productType.id = "f6a19a23-14e3-40d0-aee2-3e612fcb1bc7" and attributes.rating > 3 and (product.id = "abcd9a23-14e3-40d0-aee2-3e612fcbefgh" or product.id = "ba3e4ee7-30fa-400b-8155-46ebf423d793") // matches a line item that has the Custom Field "gender" to be "alien" custom.gender = "alien" //matches a line item that is not in a given category categories.id != ("f6a19a23-14e3-40d0-aee2-3e612fcb1bc7") ``` ### CustomLineItem field identifiers The following identifiers reference fields on a [Order](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AOrder)'s [CustomLineItems](https://docs.commercetools.com/api/projects/carts.md#customlineitem). You can only use CustomLineItem predicate field identifiers for the following: - As a part of a [Order Predicate Function](https://docs.commercetools.com/api/projects/predicates.md#order-predicate-functions). - `money` - [MoneyString](https://docs.commercetools.com/api/projects/predicates.md#moneystring) - `money.centAmount` - Number - `money.currencyCode` - [CurrencyCode](https://docs.commercetools.com/api/types.md#currencycode) - `slug` - String - `quantity` - Number This field cannot be used in predicates for [MultiBuyCustomLineItemsTarget](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AMultiBuyCustomLineItemsTarget) or [CartDiscountPatternTarget](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3ACartDiscountPatternTarget) predicates. - `taxCategory.id` - String - `taxCategory.key` - String - `taxRate` - [TaxRate field identifiers](https://docs.commercetools.com/api/projects/predicates.md#taxrate-field-identifiers) - `custom.` - [CustomField](https://docs.commercetools.com/api/projects/custom-fields.md#customfields) Matches a Custom Field on the custom line item by its name given a certain [predicate](https://docs.commercetools.com/api/projects/predicates.md#customfield-field-identifiers). - `custom.type.id` - `id` of a [Type](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AType) - `custom.type.key` - `key` of a [Type](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AType) #### CustomLineItem predicate examples ```javascript // matches all custom line items true // matches custom line items with price of individual items bigger than 10.50 EUR only if the price is a net price money > "10.50 EUR" and taxRate.includedInPrice = false // matches a custom line item by slug slug = "adidas-superstar-2" // matches a custom line item that has the Custom Field "gender" to be "alien" custom.gender = "alien" ``` ### CustomField field identifiers The following identifiers reference Custom Fields on an [Order](https://docs.commercetools.com/urn?urn=ctp%3Aapi%3Atype%3AOrder), or a line item in a order. You can use CustomField field identifiers for the following: - `custom.` - [CustomField](https://docs.commercetools.com/api/projects/custom-fields.md#customfields) Matches a Custom Field by its name. If a field name contains a dash (-) or starts with a digit, escape it using backticks (\`): `` custom.\`1stYear\` `` #### Supported Custom Field types The following [field types](https://docs.commercetools.com/api/projects/types.md#fieldtype) are supported as individual values or as [Sets](https://docs.commercetools.com/api/projects/types.md#customfieldsettype): - `Boolean` - `String` - `Number` - `DateTime` - `Date` - `Time` - `Enum` - `LocalizedEnum` - `Reference` Custom Fields using the `Money` type are also supported, but [Sets](https://docs.commercetools.com/api/projects/types.md#customfieldsettype) with the `Money` type are not supported. #### CustomField predicate examples Predicates on a `reference` match on the ID. Examples: ```javascript //identifies a Custom Field by ID (where the field is a Reference type) custom. = "" //checks if a Custom Field is contained in a collection, where the field is a reference type custom. contains any ("", "") //checks if a Custom Field has a value equal to 18.00 EUR, if the field is a Money type custom. = "18.00 EUR" //checks if custom..centAmount = 18 //checks if custom..currencyCode = "EUR" ``` ### Order Predicate functions In addition to accessing specific field information, you can use the following predicate functions when constructing Order Predicates. All functions accept a [LineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#lineitem-field-identifiers) or [CustomLineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#customlineitem-field-identifiers) as an argument, which allows you to limit function to a subset of matching (custom) line items. You can also provide a simple predicate, like `true`, as an argument if you want to sum or count all line items. - `lineItemCount`(`predicate`: [LineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#lineitem-field-identifiers)) – Number Counts matching line items. - `customLineItemCount`(`predicate`: [CustomLineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#customlineitem-field-identifiers)) – Number Counts matching custom line items. - `lineItemTotal`(`predicate`: [LineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#lineitem-field-identifiers)) – [Money](https://docs.commercetools.com/api/types.md#money) Sums the total of matching line items. - `customLineItemTotal`(`predicate`: [CustomLineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#customlineitem-field-identifiers)) – [Money](https://docs.commercetools.com/api/types.md#money) Sums the `quantity * money` of matching custom line items. - `lineItemNetTotal`(`predicate`: [LineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#lineitem-field-identifiers)) – [Money](https://docs.commercetools.com/api/types.md#money) Sums the total of matching line items only if the price is a net price (only valid for tax-exclusive `taxRate`). - `customLineItemNetTotal`(`predicate`: [CustomLineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#customlineitem-field-identifiers)) – [Money](https://docs.commercetools.com/api/types.md#money) Sums the `quantity * money` of matching custom line items only if the price is a net price (only valid for tax-exclusive `taxRate`). - `lineItemGrossTotal`(`predicate`: [LineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#lineitem-field-identifiers)) – [Money](https://docs.commercetools.com/api/types.md#money) Sums the total of matching line items only if the price is a gross price (only valid for tax-inclusive `taxRate`). - `customLineItemGrossTotal`(`predicate`: [CustomLineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#customlineitem-field-identifiers)) – [Money](https://docs.commercetools.com/api/types.md#money) Sums the `quantity * money` of matching custom line items only if the price is a gross price (only valid for tax-inclusive `taxRate`). - `lineItemExists`(`predicate`: [LineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#lineitem-field-identifiers)) – Boolean Returns true if at least one line item matches the predicate, otherwise false. - `forAllLineItems`(`predicate`: [LineItemPredicate](https://docs.commercetools.com/api/projects/predicates.md#lineitem-field-identifiers)) – Boolean Returns true if all line items matching the predicate, otherwise false. The total of a line item depends on the [line item price mode](https://docs.commercetools.com/api/projects/carts.md#lineitempricemode) and the discounts that may apply. ### Order Predicate examples ```javascript // matches an order with total line item cost bigger or equal to 10 USD (which excludes other costs, like shipping) lineItemTotal(true) > "10.00 USD" // matches an order only when it has exactly 2 like items that have product with size "xxl" or "xl" lineItemCount(attributes.size in ("xxl", "xl")) = 2 // matches an order by customer information customer.email = "john@example.com" and customer.customerGroup.id = "f6a19a23-14e3-40d0-aee2-3e612fcb1bc7" // matches an order with a minimum total price and at least one lineItem that satisfies a price, a productType, a size attribute or a specific product totalPrice > "800.00 EUR" and lineItemCount(price > "10.50 EUR" and productType.id = "f6a19a23-14e3-40d0-aee2-3e612fcb1bc7" and attributes.size in ("xl", "xxl") or product.id = "abcd9a23-14e3-40d0-aee2-3e612fcbefgh") > 0 // matches an order with custom.bookingStart = 2016-11-24 and custom.bookingEnd = 2016-12-04 custom.bookingStart = "2016-11-24" and custom.bookingEnd = "2016-12-04" // matches an order for a family (at least 2 adults and at least one youth) lineItemCount(custom.age = "adult") >=2 and lineItemCount(custom.age = "youth") >=1 ``` ## Related pages - [Section overview page](https://docs.commercetools.com/api.md) - [Previous page: Discount Predicates](https://docs.commercetools.com/api/predicates/predicate-operators.md)