Every X discount Y
How the every X discount Y action works, what are the required and optional parameters to set it up, and the resources for which it's enabled
Actions of type every_x_discount_y
enable you a fixed amount discount of value y
on the selected items for each interval defined by the value x
on the amount of a desired field. The total discount is proportionally distributed based on the quantity of the selected items.
If X is greater than the amount on which the intervals are supposed to be calculated, the action won't have any effect.
The action applies even when the attribute
value isn't an exact multiple of X but just greater than. The discount is proportionally distributed based on the targeted items' quantity.
This way, if the value of the specified field is n
(where n
is greater than or equal to m*x
and less than (m+1)*x
, with m
greater than zero) the total discount applied will be m*y
.
When setting up a every X discount Y action, in addition to the action type
, you need to specify at least value
object as described here (for more information on the parameters listed in the table below and how they work please refer to the main actions page):
type
Must be "every_x_discount_y"
.
selector
identifier
Can be set only if the selector
key value is an attribute.
groups
aggregation
value
Example
The following action applies a 5000 cents discount every 30000 cents of the total amount of the order, proportionally distributing the total resulting discount on the line items associated with an SKU belonging to the related condition's matchers grouped as discountable-items
:
Considering some real number:
If the total amount of the order is 60000 cents and the order contains two products — both with quantity 1 for a total of 2 units — the total discount applied will be
(60000 / 30000) * 5000 = 10000
cents, equally distributed on the two line items (10000 / 2 = 5000
cents each).If the total amount of the order is 90000 cents and the order contains two products — one with quantity 2 and the other with quantity 1 for a total of 3 units — the total discount applied will be
(90000 / 30000) * 5000 = 15000
cents, resulting in a15000 / 3 = 5000
cents discount per units, proportionally distributed on the two line items (5000 * 2 = 10000
cents on the one with quantity 2,5000 * 1 = 5000
cents on the other).If the total amount of the order is 140000 cents and the order contains three products — one with quantity 5, another with quantity 3, and the other with quantity 2, for a total of 10 units — the total discount applied will be
(140000 / 30000) * 5000 = 20000
cents, resulting in a20000 / 10 = 2000
cents discount per unit, proportionally distributed on the three line items (2000 * 5 = 10000
cents on the one with quantity 5,2000 * 3 = 6000
cents on the one with quantity 3,2000 * 2 = 4000
cents on the one with quantity 2).
Please note that when calculating the number of intervals on which to apply the y
discount, we always consider only the quotient of the division between the numeric value of the field specified in the attribute
and x
(skipping the remainder when the former isn't an exact multiple of the latter).
Value
The x
and y
values of a buy X pay Y are defined within the value
object where you can also optionally set a limit on the number of items to consider for the calculation:
x
The number (usually an amount in cents) that defines the segmentation in intervals.
y
The amount in cents to be discounted for each interval.
attribute
The field of the main resource (at the moment, orders
, since this action is available for order rules only) on which to calculate the intervals, based on the x
key (must be numeric).
Restrictions
You cannot use bundles, set a limit, or target a specific attribute on which to apply the action when setting up every X discount Y actions.
Resources
As regards the Rule Engine integration with Commerce Layer Core API, the every X discount Y action type is available for promotions (order rules) only.
Last updated