Product Price Design
1. Price Calculation
In http://dev.commercetools.com/, a product variant can have a set of prices represented as an array of
Price values. A price is defined with a scope (customer group, channel and country) and/or an optional period (valid from and/or valid to). A price has a regular value and an optional discounted price. When calculate a price, there are two steps: price selection and discount checking.
1.1. Price Selection
First, the scope and period are used to select the prices of a product variant. The result should be a single
In price filtering, the field priority order is
customer group >
country, i.e., the
customer group has the highest priority and the
country the lowest. If a field is missing in price, that it matches all.
1.2. Discounted Price
For a elected price, use the
value in the
discounted field if the
discounted field is set, otherwise, use the
value field in the price.
discounted field is set when there is a (and only one) matching
2. Data Types
A price data has the following important fields (only
value are required fields):
- id: a UUID string.
- value: a
Moneyvalue that has a
- country: a two-digit country code as per ISO 3166-1 alpha-2.
- customerGroup: reference to a
- channel: a reference to a channel.
- validFrom: a datetime value from which the price is valid.
- validUntil: a datetime value until which the price is valid.
- discounted: a
DiscountedPricevalue that has two fields:
valueand a reference to a matching
The important fields are the following:
- id: a UUID string
- version: the current version
- value: the type of the dicount, can be
external. If it is
DiscountedPriceis the discounted price.
- predicate: a string that defines which product prices should be reduced. Products, variants, categories and prices can be used to define the matching criteria.
- sortOrder: a string contains a number between 0 and 1. A greater value is prioritzed higher than a lower value.
- isActive: a boolean value of the active status.
- references: an array of references to all matching resources.