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.
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:
"actions": [
{
"type": "every_x_discount_y",
"selector": "order.line_items.sku",
"groups": [ "discountable-items" ],
"value": {
"x": 30000,
"y": 5000,
"attribute": "total_amount_cents"
}
}
]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 = 10000cents, equally distributed on the two line items (10000 / 2 = 5000cents 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 = 15000cents, resulting in a15000 / 3 = 5000cents discount per units, proportionally distributed on the two line items (5000 * 2 = 10000cents on the one with quantity 2,5000 * 1 = 5000cents 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 = 20000cents, resulting in a20000 / 10 = 2000cents discount per unit, proportionally distributed on the three line items (2000 * 5 = 10000cents on the one with quantity 5,2000 * 3 = 6000cents on the one with quantity 3,2000 * 2 = 4000cents on the one with quantity 2).
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
Resources
Last updated